Default injected service name
We need to give the user the possibility of avoiding automatic injection of the preferences service in all routes, controllers and components.
Also, we need to give the user the possibility of changing the default preferences key we're using to inject the service on said objects (routes, controllers and components).
Add the following key to preferences.js configuration file:
export default {
inject: ...
};
When
-
injectvalue isfalsethen deactivate the automatic injection -
injectis not defined then apply the default (current) behavior (injecting the service on every route, controller and component as the keypreferences).
Also add the following key
export default {
name: 'foo'
};
Where name defines the property name to use in every route, controller and component for the service:preferences injection.
We'll need to update the preference compute property to use the name setting.
Example:
preference.js
export default {
name: 'userSettings'
}
a-component.js
import Ember from 'ember';
import preference from 'ember-preferences/computed';
export default Ember.Component.extend({
foo: preference('bar')
});
In this case bar preference will be read from userSettings.foo, so, this will be similar to do the following:
import Ember from 'ember';
export default Ember.Component.extend({
foo: Ember.computed.alias('userSettings.bar')
});
Note that in this example service:preferences is injected on every component because the inject key is not defined in the preferences.js file.