Following exact instructions on
Ember site
generates the following ERROR
8:6 error Only string, number, symbol, boolean, null, undefined, and function are allowed as default properties ember/avoid-leaking-state-in-ember-objects
Configuration
ember-cli: 2.18.0
node: 4.8.4
os: darwin x64
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
headers: {
'Authorization': 'XXX'
}
});
What version of Ember are you using @adrianboston?
I've tracked down the issue to the build time avoid-leaking-state-in-ember-objects rule in the eslint-plugin-ember plugin. Which is trying to prevent multiple ember objects from modifying a shared object. This usually isn't an issue for headers since most ember applications only have 1 instance of any given adapters but we should probably update the documentation to recommend using Ember.computed as the default patter for defining headers.
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
headers: Ember.computed(function() {
return {
'Authorization': 'XXX'
}
})
});
@bmac that would also throw a linting error as a bad practice since there is no dependent get :P
Setting headers in init until we have constructors is likely the best recommendation.
cc @locks and @rtablada for learning team
Closing in favor of the discussion in #4496
Most helpful comment
I've tracked down the issue to the build time
avoid-leaking-state-in-ember-objectsrule in the eslint-plugin-ember plugin. Which is trying to prevent multiple ember objects from modifying a shared object. This usually isn't an issue for headers since most ember applications only have 1 instance of any given adapters but we should probably update the documentation to recommend using Ember.computed as the default patter for defining headers.