Skip to content
This repository has been archived by the owner on May 26, 2019. It is now read-only.

Remove explicit names from initializers. #1654

Merged
merged 2 commits into from
Jan 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions source/applications/initializers.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export function initialize(application) {
};

export default {
name: 'shopping-cart',
initialize: initialize
initialize
};
```

Expand All @@ -56,8 +55,7 @@ export function initialize(applicationInstance) {
}

export default {
name: 'logger',
initialize: initialize
initialize
};
```

Expand All @@ -71,9 +69,8 @@ export function initialize(application) {
};

export default {
name: 'config-reader',
before: 'websocket-init',
initialize: initialize
initialize
};
```

Expand All @@ -83,9 +80,8 @@ export function initialize(application) {
};

export default {
name: 'websocket-init',
after: 'config-reader',
initialize: initialize
initialize
};
```

Expand All @@ -95,11 +91,39 @@ export function initialize(application) {
};

export default {
name: 'asset-init',
after: ['config-reader', 'websocket-init'],
initialize: initialize
initialize
};
```

Note that ordering only applies to initializers of the same type (i.e. application or application instance).
Application initializers will always run before application instance initializers.

## Customizing Initializer Names

By default initializer names are derived from their module name. This initializer will be given the name `logger`:

```app/instance-initializers/logger.js
export function initialize(applicationInstance) {
let logger = applicationInstance.lookup('logger:main');
logger.log('Hello from the instance initializer!');
}

export default { initialize };
```

If you want to change the name you can simply rename the file, but if needed you can also specify the name explicitly:

```app/instance-initializers/logger.js
export function initialize(applicationInstance) {
let logger = applicationInstance.lookup('logger:main');
logger.log('Hello from the instance initializer!');
}

export default {
name: 'my-logger',
initialize
};
```

This initializer will now have the name `my-logger`.