How to refactor initializers to ember-cli?


#1

I am calling my initializers like this (in app.js):

loadInitializers(App, 'preloadData');

The initializer is defined in app/initializers/preload-data.js like this:

export default {
    name : 'preloadData',
    initialize : function (container, application) { ... }
};

Is the filename important? Should it be called preload-data.js or preloadData.js? Why? Where is this documented?

Why the redundant ‘name’ property for the exported symbol? (usually the ember-cli resolver looks things up based on the filename of the exported symbol, and does not need any extra manual namespacing)

In any case, my initializers are not being triggered.

Thanks,

DanG


#2

You don’t need to load your initializers, they should be picked up automatically based on the fact that they are defined in the ‘initializer’ namespace.

Initializer names are required, must be unique and do not necessarily correspond to the filename of the module in which they are defined. initializers are a general Ember mechanism that predates ember-cli and the use of modules for organizing your app’s codebase.


#3

I figured out the problem by creating a dummy initializer with ember-cli (which seems is the only “documentation” currently available for ember-cli)

I do not need to manually load the initializers, but do:

loadInitializers(App, config.modulePrefix);

The name of the files do not seem to matter …


#4

Thanks Ifridael, indeed that is right.