Last active
September 26, 2018 04:46
-
-
Save rafaltrojanowski/9752bc936d36f2de0a5338abb8e092fb to your computer and use it in GitHub Desktop.
component-refractor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@ember/component'; // modern syntax | |
export default Component.extend({ // redundant Ember, that has been already imported. | |
count: 1, // it will start from 2, imho it should be 0 | |
// Use didInsertElement hook instead of init. | |
// I assume that we want to start updating counter begining from the moment when the element was inserted to the DOM. | |
// `init` is called before didInsertElement() and would lead to some | |
// init() does several things behind the scenes. | |
// `init` hook would require calling `this._super(...arguments);` | |
// the only use-case when I use init hook is to set Component related state like internal errors: | |
// Example: | |
// init() { | |
// this._super(...arguments); | |
// this.set('errors', []); | |
// } | |
// Error: Assertion Failed: You must call `this._supe | |
didInsertElement() { | |
this.updateCounter(); | |
}, | |
updateCounter() { | |
this.incrementProperty('count') | |
Ember.run.later(this, this.updateCounter, 1000) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment