Skip to content

Commit 5643369

Browse files
committed
Adding docs for no-lifecycle-events
1 parent 4905ff1 commit 5643369

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

guides/rules/no-lifecycle-events.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# No Lifecycle Events
2+
3+
Ember tracks changes and notifies listeners of those changes. This is quite powerful, and prevents “glue” code to propagate changes. This also enables granular updates, rather than whole-world rebuild scenarios. This comes at a downside, we can easily accidentally (today) trigger these “update” code-paths, when they are not required. This comes largely at a performance cost. For example, if during initial render we are actually also re-rendering. This is wasteful. Ember keeps getting better at detecting these cases and informing the developer. Unfortunately it is not perfect yet. When we use the lifecycle events we are incuring double work as we must event and also call the method hooks on the object. Because of this we should simply do the work in a [lifecycle hook](https://guides.emberjs.com/v2.10.0/components/the-component-lifecycle/).
4+
5+
```
6+
// Good
7+
export default Ember.Component.extend({
8+
init() { // good example
9+
this._super(...arguments);
10+
this.set('first', 'stefan');
11+
this.set('last', 'Penner');
12+
}
13+
});
14+
```
15+
16+
```
17+
// Bad
18+
export default Ember.Component.extend({
19+
setup: Ember.on('init', function() {
20+
this._super(...arguments);
21+
this.set('first', 'stefan');
22+
this.set('last', 'Penner');
23+
})
24+
});
25+
```

0 commit comments

Comments
 (0)