Last active
September 25, 2018 19:02
-
-
Save visoft/cf7edf8e72f8f1d0ccf3af91bc45a23c to your computer and use it in GitHub Desktop.
Ember Sample Counter
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'; | |
import { later } from '@ember/runloop'; | |
export default Component.extend({ | |
count: 0, | |
timerStatus: 1, | |
init() { | |
this._super(...arguments); | |
this.updateCounter(); | |
}, | |
updateCounter() { | |
if (this.timerStatus) { | |
this.incrementProperty('count'); | |
later(this, this.updateCounter, 1000); | |
} | |
}, | |
actions: { | |
startCounter() { | |
this.set('timerStatus', 1); | |
this.updateCounter(); | |
}, | |
stopCounter() { | |
this.set('timerStatus', 0); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment