-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate Ember object types in resolver #11261
Validate Ember object types in resolver #11261
Conversation
let expectedType = VALIDATED_TYPES[parsedName.type]; | ||
|
||
Ember.assert(`Expected ${parsedName.fullName} to resolve to an ${expectedType} but instead it was ${resolvedType}.`, function() { | ||
return !expectedType || expectedType.detect(resolvedType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that we stamp the objects in question, instead of checking that they are a specific class.
The idea here is that at some point in the not terribly distant future, we do not want components/views to have to be a specific instance (they might be "POJO's" that adhere to our view systems requirements). Ember.Component
already adds isComponent
to the instances, we could do the same to the factories.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not understanding the object stamping approach yet. It seems like if components can be POJOs then they shouldn't be validated. This kind of validation only makes sense to me for objects that are integrated with Ember through private APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed with @mitchlloyd in slack. I think he has a path forward...
This will definitely help folks accidentally exporting the wrong thing for sure. Thanks for tackling! Can you confirm that both the internal default resolver, and the ember-cli modules resolver follow the same path? |
67394f7
to
c299645
Compare
This has been updated to use the factory stamping approach we discussed. Notice that I renamed |
|
||
forEach(types, function(type) { | ||
let matcher = new RegExp(`to resolve to an Ember.${capitalize(type)}`); | ||
throws(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ember.assert statements are stripped from production builds, so the prod Travis run is failing (since nothing is thrown). We need to use 'expectAssertion' here, and that helper function will handle the prod case for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha! Now I know why expectAssertion
exists :)
This commit adds assertions to ensure that some key object types are validated when they are resolved: * Routes * Components * Views * Services I did not add a validation for controller classes because the implementation for detection would need to be a little different and some of Ember's tests play fast (and loose) with with the types of things they try to pass off as controllers. For now I don't think this additional validation is worth adding given imminent demise of Controllers.
c299645
to
a876722
Compare
Also, I have an Ember CLI app that I tested with to make sure that the |
…roller Validate Ember object types in resolver
Thank you! |
This seems like it would make it harder to have simple Mock classes in testing that do not have to extend from the actual real Service/Component/etc? |
@igorT - There is no requirement to extend from a particular object. We used a brand specifically to allow it to be overridden fairly easily ( |
After discussing in detail with @fivetanley and @igorT, this is a breaking change (Ember Data registers the store as a service, and now it results in an assertion) for services. We need to change the service assertion into a deprecation (which still provides some helpful information) and then we can change to an assertion in 2.0.0. |
Makes sense. I was worried about services
|
@mitchlloyd - I'd love the help on it, no one is tackling yet AFAIK. |
wait, what if i want to export something else? I suppose just duck type it to have the appropriate flag? This is likely a breaking change, we should deprecate/warn for a cycle first. |
This broke my app. I had a It was easy enough to is the |
@raytiley it's been updated on master to only deprecate |
@stefanpenner thanks. I'm locked into beta right now but will give canary a whirl soon |
@raytiley - Ugh, sorry man. @stefanpenner - Not the component assertion. The only one that was changed to a deprecation was for Service. I guess we should also make the component assertion into a deprecation for now. The practice that @raytiley mentions is fairly common (I have used it a few times to get a view usable by name in handlebars). |
I made an update here: #11300 |
Since Ember 1.13, Ember expects that services either extend `Ember.Service`, or they must set `isServiceFactory` to `true` at the class level. Since the Cart service already extends `ArrayProxy`, this commit reopens the Cart service class to set `isServiceFactory` to `true`. See emberjs/ember.js#11261
Since Ember 1.13, Ember expects that services either extend `Ember.Service`, or they must set `isServiceFactory` to `true` at the class level. Since the Cart service already extends `ArrayProxy`, this commit reopens the Cart service class to set `isServiceFactory` to `true`. See emberjs/ember.js#11261
@rwjblue This is to address #11212.
This commit adds assertions to ensure that some key object types
are validated when they are resolved:
I did not add a validation for controller classes because the
implementation for detection would need to be a little different (can't
simply use #detect). Also some of Ember's tests play fast (and loose)
with with the types of things they try to pass off as controllers. For
now I don't think this additional validation is worth adding given
imminent demise of Controllers.