Skip to content

Instantly share code, notes, and snippets.

@marialomidze
Last active November 2, 2017 20:47
Show Gist options
  • Select an option

  • Save marialomidze/02c91d6fdf1c677351c7351900ca70a3 to your computer and use it in GitHub Desktop.

Select an option

Save marialomidze/02c91d6fdf1c677351c7351900ca70a3 to your computer and use it in GitHub Desktop.
ember-concurrency
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
const {
Component,
set,
get
} = Ember;
export default Component.extend({
isSubmitting: false,
waitToLoad: task(function * () {
yield timeout(2000);
set(this, 'progress', 'I will run for 5 more seconds.');
yield timeout(5000);
set(this, 'progress', 'I am done');
}),
actions: {
submit() {
set(this, 'isSubmitting', true);
// do some stuff ...
// ...
// ...
set(this, 'isSubmitting', false);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
{{button-component}}
{{progress}}
<div>
<button onclick={{action 'submit'}}>
{{#if isSubmitting}}
Loading...
{{else}}
Submit
{{/if}}
</button>
</div>
<div>
<button onclick={{perform waitToLoad}}>
{{#if waitToLoad.isIdle}}
Submit
{{else}}
Loading...
{{/if}}
</button>
<button onclick={{cancel-all waitToLoad}}>
Cancel
</button>
<br>
{{progress}}
</div>
{
"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": "latest"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment