Skip to content

Instantly share code, notes, and snippets.

@visoft
Last active September 25, 2018 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visoft/cf7edf8e72f8f1d0ccf3af91bc45a23c to your computer and use it in GitHub Desktop.
Save visoft/cf7edf8e72f8f1d0ccf3af91bc45a23c to your computer and use it in GitHub Desktop.
Ember Sample Counter
{{counter-component}}
{{outlet}}
{{count}}
<button {{action "stopCounter"}}>Stop</button>
<button {{action "startCounter"}}>Start</button>
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