Skip to content

Instantly share code, notes, and snippets.

@tzellman
Last active April 4, 2017 09:22
Show Gist options
  • Save tzellman/acfaa7b515e147abd35834e21fa099fd to your computer and use it in GitHub Desktop.
Save tzellman/acfaa7b515e147abd35834e21fa099fd to your computer and use it in GitHub Desktop.
EC orchestration
import Ember from 'ember';
import {task, timeout} from 'ember-concurrency';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
inputValue: 0,
numProcessed: 0,
onValueChange: Ember.observer("inputValue", function(){
this.get("processSoon").perform(this.get("inputValue"));
}),
longRunningTask: task(function*(value){
yield timeout(2000); //simulate a long operation
this.incrementProperty("numProcessed", 1);
return value;
}).drop(),
processSoon: task(function*(value){
yield timeout(500); //debounce
yield this.get("longRunningTask").perform(value);
}).restartable()
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<button onclick={{action (mut inputValue) (add inputValue 1)}}>Clicks {{inputValue}}</button>
<br>
{{#if longRunningTask.isRunning}}
<h2>Running Long Process...</h2>
{{/if}}
{{#if longRunningTask.lastSuccessful}}
<h3>Processed {{numProcessed}} {{if (eq numProcessed 1) "click" "clicks"}}: (click #{{longRunningTask.lastSuccessful.value}})</h3>
{{/if}}
<br>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1",
"ember-concurrency": "0.7.19",
"ember-math-helpers": "2.0.5",
"ember-truth-helpers": "1.3.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment