-
-
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
Execute initializers in their respective context #10179
Conversation
👍, although we should probably discuss whether this needs to be flagged and/or is a breaking change as written. |
@trek Ahh yeah, I wasn't sure about that. Let me know if you think it needs to be behind a flag and I'll update. |
Off the top of my head I can't think of a sensible reason to rely on global execution, but that doesn't mean it's not a possibly widely used "feature" that we can't break for 2.0. I'll add it to agenda for the next core team meeting. |
@trek Splendid, thank you! |
This seems like an improvement to me, but we should definitely get it feature flagged. |
@@ -693,9 +693,15 @@ var Application = Namespace.extend(DeferredMixin, { | |||
var namespace = this; | |||
var initializer; | |||
|
|||
var makeGraphValue = function(initializer) { | |||
return function() { | |||
return initializer.initialize.apply(initializer, arguments); |
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.
The arguments are known, why not just specify them (as opposed to calling apply
)?
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.
@rwjblue It may may helpful when adding/changing the arguments of initialize function in future (not sure).
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.
@manoharank @rwjblue Indeed, future-proofing was my intent here.
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.
Using apply
is slower than just calling the function and if we refactor the arguments then this may need to be updated anyways (along with many other things). tldr; I would prefer to just invoke the function with the params that we know.
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.
@rwjblue We can't simply call the function, we need to use either call
or apply
. I can update the PR to use call
with named arguments if you would prefer?
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.
@gf3 - Did you test it as I suggested? Calling a function from an object should set this
inside the function to the object that it was called from.
return initializer.initialize(container, application);
Sample JSBin: http://jsbin.com/wefas/1/edit?html,js,output
a97c19e
to
e7c58f6
Compare
@gf3 yes please. |
a9e1f2e
to
bbb7659
Compare
bbb7659
to
f70f31f
Compare
@@ -14,7 +14,8 @@ | |||
"new-computed-syntax": null, | |||
"ember-testing-checkbox-helpers": null, | |||
"ember-metal-stream": null, | |||
"ember-htmlbars-each-with-index": true | |||
"ember-htmlbars-each-with-index": true, | |||
"ember-initializer-context": null |
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.
We typically like to use the package name as the prefix. Can you update to ember-application-initializer-context
?
…in their respective context
f70f31f
to
90cbc09
Compare
Execute initializers in their respective context
@gf3 - Thanks! |
The initializer API has changed as of 2.X, the blueprints need to be updated to address those changes. See also: emberjs/ember.js#10179
The initializer API has changed as of 2.X, the blueprints need to be updated to address those changes. See also: emberjs/ember.js#10179
…updated to address those changes. See: emberjs/ember.js#10179
…updated to address those changes. See also: emberjs/ember.js#10179
…updated to address those changes. See also: emberjs/ember.js#10179
[Safe for 2.1] Update initializer blueprint. Fixes the test blueprint to invoke the initializer in a way such that `this` is set. See: emberjs/ember.js#10179
[Safe for 2.1] Update initializer blueprint. Fixes the test blueprint to invoke the initializer in a way such that `this` is set. See: emberjs/ember.js#10179
[Safe for 2.1] Update initializer blueprint. Fixes the test blueprint to invoke the initializer in a way such that `this` is set. See: emberjs/ember.js#10179
Currently initializers are executed in the global context; this small but useful change will execute the
initialize
function in the context of its object. Below is an example of where something like this would come in handy. In the example sometimes it's useful (especially with testing) to be able to resetapp-state
or to switch out various app states at different times.