Skip to content

Instantly share code, notes, and snippets.

@machty
Last active April 30, 2018 15:52
Show Gist options
  • Save machty/db930bdb658035626a9be9268bc39845 to your computer and use it in GitHub Desktop.
Save machty/db930bdb658035626a9be9268bc39845 to your computer and use it in GitHub Desktop.
ember-concurrency starter
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
myTask: task(function * () {
let didConfirm = yield this.get('getConfirmation').perform("Are you sure?");
if (didConfirm) {
alert("woot");
}
}),
confirmation: null,
getConfirmation: task(function * (prompt) {
try {
let defer = Ember.RSVP.defer();
this.set('confirmation', {
resolve: defer.resolve,
prompt
});
return yield defer.promise;
} finally {
this.set('confirmation', null);
}
})
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<p>
myTask is {{if myTask.isRunning 'running' 'NOT running'}}
</p>
<button onclick={{perform myTask}}>perform MyTask</button>
{{#if confirmation}}
<h5>Confirm</h5>
<p>
{{confirmation.prompt}}
</p>
<button onclick={{action confirmation.resolve false}}>
Cancel
</button>
<button onclick={{action confirmation.resolve true}}>
Yes
</button>
{{/if}}
{
"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