ember-cli / ember-cli/eslint-plugin-ember
avoid-leaking-state missing case example
- Dominant language
- JavaScript
- Stars
- 263
- Forks
- 214
- Avg merge
- 30m
- Merged PRs (30d)
- 5
Description
https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/avoid-leaking-state-in-ember-objects.md
Hey,
I see a problem with `good` example which doesn't replace the `bad` example functionality in 100%. If you would set properties in `init` hook you will lose a possibility to override it by passing it during creation.
A full example of the problem:
```js
let leakingState = EmberObject.extend({
items: []
});
leakingState.create({ items: [1,2,3] });
// I know the state is leaking but user expect to get a passed list
leakingState.get('items') // returns [1,2,3] OK!
let NoLeakingState = EmberObject.extend({
init() {
this._super(...arguments);
this.items = [];
},
});
NoLeakingState.create({ items: [1,2,3] });
NoLeakingState.get('items') // returns [] NOT OK!
// A suggested solution
let NoLeakingStateNew = EmberObject.extend({
items: computed(function() {
return [];
})
});
NoLeakingStateNew.create({ items: [1,2,3] });
NoLeakingStateNew.get('items') // returns [1,2,3] OK!
```
So, we should add a new example with explanation of the problem or replace it. I know, it depends on the use case but in my opinion, a much more common expected behavior is the one with the computed.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.