Skip to content

Instantly share code, notes, and snippets.

@machty
Created November 18, 2016 16:28
Show Gist options
  • Save machty/a7fe659f428a09e4eb5da69415856976 to your computer and use it in GitHub Desktop.
Save machty/a7fe659f428a09e4eb5da69415856976 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import { task, timeout, asyncComputed, emit } from 'ember-concurrency';
export default Ember.Controller.extend({
value: 123,
tweened: asyncComputed('value', function * (v) {
let targetValue = parseInt(v);
let curValue = parseInt(this.get('tweened.lastComplete.value') || targetValue);
while (true) {
let delta = Math.floor((targetValue - curValue) * 0.6);
if (delta) {
curValue += delta;
yield emit(curValue);
} else {
return targetValue;
}
yield timeout(50);
}
}),
});
<h3>ember-concurrency async computed properties</h3>
<p>{{input value=value type='number'}}</p>
<h1>{{tweened.value}}</h1>
{
"version": "0.10.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {
"ember-concurrency": "tof3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment