-
Notifications
You must be signed in to change notification settings - Fork 0
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
Is it possible to add initializer directly from the code of an ember-cli addon? #14
Comments
tl;dr: Not without explicitly configuring that initializer in the This is not working because you're executing the initializer function too late in the booting process. The The initializer from a Component module will only be called when the module is imported. Earliest that the module will be imported is when an instance of this component is created for the first time. Why are you trying to put your initializer into a Component module? |
FYI: @tomdale description of the Ember application booting process ^^ coincidentally, answered to you :) |
So the difference to the process described by Tom Dale is that add-on modules are evaluated lazily in ember-cli apps. Is it right? And, probably, if there is no initializer in the In my current setup if I import a component I can have initializers in the same file (because it's the step 4 as per Tom's answer). Looking for the best way to port it to ember-cli:
so this cannot be used as-is in ember-cli projects. Thanks for the answer and for the links to ember-cli example. That's what I need. |
All of the ES6 modules are evaluated when they're necessary.
If you have an EmberCLI addon that has a component and an initializer then you should include in the initializer in the addon's
Yes, this make sense.
Don't do this ^^. If you're moving your addon to EmberCLI then you should just split up your component into a separate initializer file and a component file and place them in correct directories in your addon. A common structure for an addon might look like this:
/addon/components/my-component.jsimport Ember from 'ember';
export default Ember.Component.extend({
// your component code goes here
}); /addon/initializers/my-initializer.jsexport function initialize() {
// actually initialization code
}
export default {
name: 'my-component initializer',
initialize: initialize
} /app/components/my-component.jsimport MyComponent from 'my-addon/components/my-component';
export default MyComponent: /app/initializers/my-initializer.js
This might look like duplication of effort, but /addon directory and /app directory in your addon serve different purposes. /addon/ directory is the library that your addon provides. /app/ is merged into an app when an app that's using the addon is being compiled. In a sense, you're providing code that's merged into the app and it's using the library that your addon provides. What does your initializer do? |
I see. In my non-ember-cli case initializers usually just register corresponding components. So I guess in ember-cli I don't need initializers just for registering components if I re-export components via the |
Yes. |
Thanks! The |
For example,
It didn't work for me but since I don't use ember-cli a lot I am not really sure if this is supported. So is it possible? or one has to create a file in the
initializers
folder?The text was updated successfully, but these errors were encountered: