Last active
August 29, 2015 14:28
-
-
Save rondale-sc/d7e78ce7132882773232 to your computer and use it in GitHub Desktop.
simple-stopwatch-bug
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
| import Ember from 'ember'; | |
| export default Ember.Component.extend({ | |
| didInitAttrs() { | |
| this.set('status', 'inactive'); | |
| }, | |
| startCounting() { | |
| this.setProperties({status: "running", startDate: new Date()}); | |
| this.updateValue() | |
| }, | |
| stopCounting() { | |
| this.setProperties({status: "stopped", stopDate: new Date()}); | |
| }, | |
| reset() { | |
| this.setProperties({status: "inactive", startDate: null, stopDate: null, value: null}); | |
| }, | |
| updateValue() { | |
| this.set('value', Math.abs(new Date() - this.get('startDate'))) | |
| if (this.get('status') === 'running') { | |
| Ember.run.next(this, this.updateValue) | |
| } | |
| }, | |
| actions: { | |
| toggle() { | |
| if (this.get('status') === 'inactive') { | |
| this.startCounting() | |
| } else if (this.get('status') === 'running') { | |
| this.stopCounting() | |
| } else if (this.get('status') === 'stopped') { | |
| this.reset() | |
| } | |
| } | |
| } | |
| }); |
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
| import Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| appName:'Ember Twiddle', | |
| asyncWithRunLater() { | |
| Ember.run.later(function(){ | |
| console.log('yay!'); | |
| }, 5000) | |
| }, | |
| asyncWithsetTimeout() { | |
| window.setTimeout(function(){ | |
| console.log('yay!'); | |
| }, 5000) | |
| }, | |
| actions: { | |
| wut() { | |
| this.asyncWithRunLater(); | |
| }, | |
| fine() { | |
| this.asyncWithsetTimeout(); | |
| } | |
| } | |
| }); |
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
| { | |
| "version": "0.4.8", | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.0.0/ember.js", | |
| "ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.0.0/ember-template-compiler.js" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment