Skip to content

Instantly share code, notes, and snippets.

@allthesignals
Last active March 30, 2018 16:28
Show Gist options
  • Select an option

  • Save allthesignals/fff06c36c9f27525149e126d86e52822 to your computer and use it in GitHub Desktop.

Select an option

Save allthesignals/fff06c36c9f27525149e126d86e52822 to your computer and use it in GitHub Desktop.
Ember data tasks notifyAfterLoad example
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
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!' };
})
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{model.taskInstance.value.message}}
{{log model}}
<br>
<br>
<h1>Loading!...</h1>
{
"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