Guest User

Untitled

a guest
Oct 17th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import Ember from 'ember';
  2. import { task, waitForProperty, timeout } from 'ember-concurrency';
  3.  
  4. const promptTask = task({
  5. answer: undefined,
  6.  
  7. * perform() {
  8. yield waitForProperty(this, 'answer', a => a !== undefined);
  9. return this.answer;
  10. }
  11. });
  12.  
  13. export default Ember.Controller.extend({
  14. appName: 'Ember Twiddle',
  15.  
  16. main: task(function * () {
  17. let confirmed = yield this.confirm.perform();
  18.  
  19. if (!confirmed) {
  20. return;
  21. }
  22.  
  23. let name = yield this.promptForName.perform();
  24.  
  25. yield this.work.perform(name);
  26. }),
  27.  
  28. confirm: promptTask,
  29. promptForName: promptTask,
  30.  
  31. work: task({
  32. name: null,
  33.  
  34. * perform(name) {
  35. this.set('name', name);
  36. yield timeout(3000);
  37. }
  38. })
  39. });
Add Comment
Please, Sign In to add comment