Skip to content

Instantly share code, notes, and snippets.

@RyanHirsch
Created January 9, 2015 17:35
Show Gist options
  • Select an option

  • Save RyanHirsch/c1b142db41a753070878 to your computer and use it in GitHub Desktop.

Select an option

Save RyanHirsch/c1b142db41a753070878 to your computer and use it in GitHub Desktop.
// services/clock.js
import Ember from 'ember';
export default Ember.Object.extend({
pulse: Ember.computed.oneWay('_seconds').readOnly(),
minutePulse: Ember.computed.oneWay('_minutes').readOnly(),
tick: function () {
var clock = this;
Ember.run.later(function () {
var seconds = clock.get('_seconds');
var minutes = clock.get('_minutes');
if (typeof seconds === 'number') {
clock.set('_seconds', seconds + 1);
if(Math.floor((seconds + 1) / 60) > minutes) {
clock.set('_minutes', minutes + 1);
}
}
}, 1000);
}.observes('_seconds').on('init'),
_seconds: 0,
_minutes: 0
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment