Skip to content

Commit 1d7829c

Browse files
authored
Merge pull request #19 from chadhietala/add-attrs-snapshot-doc
Adding docs for no-attrs-snapshot
2 parents 29088d2 + 27266a5 commit 1d7829c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

guides/rules/no-attrs-snapshot.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# No `attrs` snapshots
2+
3+
In 2.0.0 [`didRecieveAttrs`](https://guides.emberjs.com/v2.9.0/components/the-component-lifecycle/#toc_formatting-component-attributes-with-code-didreceiveattrs-code) and [`didUpdateAttrs`](https://guides.emberjs.com/v2.9.0/components/the-component-lifecycle/#toc_resetting-presentation-state-on-attribute-change-with-code-didupdateattrs-code) hooks were introduced are called whenever the arguments to a component referencially change. These hooks do recieve params to them, however one should not use them as they force those objects to reify which can be very costly when you have a lot of components on the page. These arguments are also purposly undocumented. If for some reason you need to do a comparison of arguments we suggest that you simply keep a cache on the component.
4+
5+
```
6+
export default Ember.Component({
7+
init() {
8+
this._super(...arguments);
9+
this._valueCache = this.value;
10+
this.updated = false;
11+
},
12+
didReceiveAttrs() {
13+
if (this._valueCache !== this.value) {
14+
this._valueCache = this.value;
15+
this.set('updated', true);
16+
} else {
17+
this.set('updated', false);
18+
}
19+
}
20+
});
21+
```

0 commit comments

Comments
 (0)