1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/components/gh-task-button.js
Austin Burdine e772430bd6 Introducing Concurrency (#147)
* deps: ember-concurrency@0.7.8

* initial conversion of post & user actions to e-concurrency tasks

- add task button which handles auto-spinning of e-concurrency tasks
- fix tests
2016-08-11 07:58:38 +01:00

30 lines
1 KiB
JavaScript

import {reads} from 'ember-computed';
import {invokeAction} from 'ember-invoke-action';
import SpinButton from './gh-spin-button';
import layout from 'ghost-admin/templates/components/gh-spin-button';
/**
* Task Button works exactly like Spin button, but with one major difference:
*
* Instead of passing a "submitting" parameter (which is bound to the parent object),
* you pass an ember-concurrency task. All of the "submitting" behavior is handled automatically.
*
* As another bonus, there's no need to handle canceling the promises when something
* like a controller changes. Because the only task running is handled through this
* component, all running promises will automatically be cancelled when this
* component is removed from the DOM
*/
export default SpinButton.extend({
layout, // This is used to we don't have to re-implement the template
task: null,
submitting: reads('task.last.isRunning'),
click() {
invokeAction(this, 'action');
return this.get('task').perform();
}
});