Created
January 9, 2015 17:35
-
-
Save RyanHirsch/c1b142db41a753070878 to your computer and use it in GitHub Desktop.
Slightly modified version of http://emberjs.com/guides/cookbook/working_with_objects/continuous_redrawing_of_views/
This file contains hidden or 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
| // 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