ember-cli / ember-cli/eslint-plugin-ember
`no-side-effects` prevents caching
- Dominant language
- JavaScript
- Stars
- 263
- Forks
- 214
- Avg merge
- 30m
- Merged PRs (30d)
- 5
Description
Native getters with autotracking don't include any caching by default, and users are encouraged to implement their own caching instead in the cases where caching is important.
But the no-side-effects rule pushes them away from implementing the simplest, clearest form of caching:
```js
get thing() {
if (!this._cachedThing || this._cachedThing.isStale()) {
this._cachedThing = this.makeANewOne(); // lint error: Don't introduce side effects
}
return this._cachedThing;
}
```
Are there lots of other ways to build a cache, some of which evade this rule? Yes. But the pattern shown here is safe and any JS dev can easily invent it and is absolutely going to try it anyway, and it's 100% safe and effective in Ember.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.