Created
July 24, 2019 12:33
-
-
Save feanor07/8e3deafcac8f8858b7e4edb8ecfd8685 to your computer and use it in GitHub Desktop.
New Twiddle
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'; | |
const DURATION = 5000 | |
export default Ember.Component.extend({ | |
incrementingValue: 0, | |
foo: Ember.observer('endVal', function(){ | |
if (this.timer) { | |
Ember.run.cancel(this.timer) | |
} | |
this.startAnimation() | |
}), | |
startAnimation() { | |
let endVal = this.get('endVal') | |
let incrementingValue = this.get('incrementingValue') | |
if (endVal === incrementingValue) { | |
return | |
} | |
let range = endVal - incrementingValue | |
let increment = endVal > incrementingValue ? 1 : -1; | |
let stepTime = Math.abs(Math.floor(DURATION / range)); | |
console.log(stepTime, increment) | |
this.scheduleAnimation(stepTime, increment) | |
}, | |
scheduleAnimation(stepTime, increment) { | |
let endVal = this.get('endVal') | |
let incrementingValue = this.get('incrementingValue') | |
if (endVal === incrementingValue) { | |
return | |
} | |
let timer = Ember.run.later(this, function() { | |
let val = Math.round(incrementingValue + increment) | |
this.set('incrementingValue', val) | |
this.scheduleAnimation(stepTime, increment) | |
}, stepTime) | |
this.set('timer', timer) | |
} | |
}); |
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', | |
endVal: 137, | |
actions: { | |
fireEvent() { | |
this.set('endVal', Math.round(Math.random()*1000)) | |
} | |
} | |
}); |
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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment