Skip to content

Instantly share code, notes, and snippets.

@alexander-alvarez
Forked from machty/controllers.application.js
Last active November 21, 2016 23:11
Show Gist options
  • Save alexander-alvarez/20bb29913da39e57a04b024d519d1375 to your computer and use it in GitHub Desktop.
Save alexander-alvarez/20bb29913da39e57a04b024d519d1375 to your computer and use it in GitHub Desktop.
ember-concurrency starter
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
const {computed} = Ember;
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
myTask: task(function * (string) {
console.log("Waiting... " + string);
yield timeout(1000);
console.log("Done");
}),
inputA: ['a', 'b'],
inputB: true,
values: computed('inputA', 'inputB', function() {
const inputB = this.get('inputB');
return this.get('inputA').map((o) => this.get('myTask').perform(`${o}:${inputB}`));
})
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{#each values as |value|}}
<p>
myTask is {{if value.isRunning 'running' 'NOT running'}}
</p>
{{/each}}
<button onclick={{perform myTask}}>perform MyTask</button>
{
"version": "0.10.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.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {
"ember-concurrency": "latest"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment