Last active
March 30, 2018 16:28
-
-
Save allthesignals/fff06c36c9f27525149e126d86e52822 to your computer and use it in GitHub Desktop.
Ember data tasks notifyAfterLoad example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| import { allSettled, timeout, task } from 'ember-concurrency'; | |
| const notifyAfterLoad = function (hash, callback) { | |
| allSettled(Object.values(hash)) | |
| .then(() => { | |
| callback(hash); | |
| }); | |
| return hash; | |
| }; | |
| export default Ember.Route.extend({ | |
| model() { | |
| return notifyAfterLoad( | |
| { taskInstance: this.get('testTask').perform() }, | |
| (hash) => { alert("callback! this should happen after task is finished") } | |
| ); | |
| }, | |
| testTask: task(function* () { | |
| yield timeout(1000); | |
| console.log('timing out...'); | |
| yield timeout(1000); | |
| return { message: 'data!' }; | |
| }) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": "0.13.0", | |
| "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.16.2", | |
| "ember-template-compiler": "2.16.2", | |
| "ember-testing": "2.16.2" | |
| }, | |
| "addons": { | |
| "ember-data": "2.16.3", | |
| "ember-data-tasks": "1.0.2" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment