Skip to content

Instantly share code, notes, and snippets.

@cristinawithout
Created January 7, 2019 21:39
Show Gist options
  • Save cristinawithout/992219809f11c93698cc481783524a18 to your computer and use it in GitHub Desktop.
Save cristinawithout/992219809f11c93698cc481783524a18 to your computer and use it in GitHub Desktop.
Conditional Yield
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
export default Ember.Controller.extend({
myTask: task(function * () {
let tmp = false;
yield timeout(200);
if (tmp) {
yield timeout(200);
alert('is true');
} else {
alert('is false');
}
}),
actions: {
runTask() {
this.get('myTask').perform();
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<button {{action 'runTask'}}>Click</button>
{
"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",
"ember-concurrency": "latest"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment