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
Run initializers and instance-initializers inside engines #96
Conversation
This enables initializers and instance-initializers inside engines. The only change necessary to get instance-initializers running is altering the canonical addon/engine.js to invoke ember-load-initializers (which is analogous to what happens in app/app.js). Getting the initializers running required an extention to the Engine class. Applications run them when they're told to boot, but no equivalent step happens for child engines, so instead we run them the first time we build an engine instance.
|
||
export default Engine.extend({ | ||
modulePrefix: 'ember-blog', | ||
let Eng; |
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.
Can you tweak this to something like the following:
const modulePrefix = 'ember-blog';
const Eng = Engine.extend({
modulePrefix,
Resolver
});
loadInitializers(Eng, modulePrefix);
Reading it top to bottom like this seems easier to my brain 😝
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.
Agreed, I was just blindly copying the format of the app/app.js blueprint. This is much better.
I do not think this is quite correct. We should be running Can you another test that ensures all initializers are ran before instance initializers? I am also concerned about an initializer calling Can you also update the blueprints (here and here) to follow the recommendations in the README? |
|
You are correct, but they are called as a byproduct of calling |
Anyways, I don't think that solution really ends up being different than this. And arguably this is clearer... |
I am fine with this approach to Engine init for now, with the understanding that we will refine it when we introduce async loading of engines. |
Thanks @ef4! |
Oh, one small nitpick: this change technically makes every engine need to put ember-load-initializers into But in practice every ember-cli app already has ember-load-initializers, so it seems OK. |
Yes, and they can easily not include it if they don't need/want initializers. |
This enables initializers and instance-initializers inside engines.
The only change necessary to get instance-initializers running is altering the canonical addon/engine.js to invoke ember-load-initializers (which is analogous to what happens in app/app.js).
Getting the initializers running required an extention to the Engine class. Applications run them when they're told to boot, but no equivalent step happens for child engines, so instead we run them the first time we build an engine instance.