Skip to content

Instantly share code, notes, and snippets.

@nerdyworm
Created February 18, 2016 18:24
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 nerdyworm/058adb38832173c7596e to your computer and use it in GitHub Desktop.
Save nerdyworm/058adb38832173c7596e to your computer and use it in GitHub Desktop.
Timer
import Ember from 'ember';
export default Ember.Controller.extend({
delta: 0,
_interval: null,
startTime: null,
timer: Ember.computed('delta', function() {
const that = this;
if (this._interval === null) {
this.set('startTime', Date.now());
this._interval = setInterval(function() {
const start = that.get('startTime');
that.set('delta', Date.now() - start);
}, 1000);
}
return this.get('delta');
}),
});
<h1>Welcome to {{timer}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.5.3",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.3.1/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.3.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment