-
-
Save HenryVonfire/1fa813a76dc097feadd04b98462e3799 to your computer and use it in GitHub Desktop.
Ember Concurrency Task Model / Nested Routes
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 Concurrency Decendants' | |
}); |
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({ | |
comments: Ember.computed.or('model.{comments,previousComments}.value'), | |
isLoading: Ember.computed.reads('model.comments.isRunning'), | |
error: Ember.computed.reads('model.comments.error') | |
}); |
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({ | |
blog: Ember.computed.or('model.{blog,previousBlog}.value'), | |
isLoading: Ember.computed.reads('model.blog.isRunning'), | |
error: Ember.computed.reads('model.blog.error') | |
}); |
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 config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('blog',{path:"/blog/:blog_id"}, function (){ | |
this.route('comments', {path:"/comments"}); | |
}); | |
}); | |
export default Router; |
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 { task, timeout } from 'ember-concurrency'; | |
export default Ember.Route.extend({ | |
model: function (params){ | |
return { | |
previousComments: this.get('commentsTask.lastSuccessful'), | |
comments: this.get('commentsTask').perform() | |
}; | |
}, | |
commentsTask: task(function *(){ | |
let blog = yield this.modelFor('blog').blogTask; | |
yield timeout(1000); | |
let comments = [{title:"I love this blog!"}, {title:"I hate this blog!"}]; | |
console.log("comments:", comments); | |
return comments; | |
}) | |
.keepLatest() | |
.cancelOn('deactivate') | |
}); |
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 { task, timeout } from 'ember-concurrency'; | |
export default Ember.Route.extend({ | |
model: function (){ | |
return { | |
previousBlog: this.get('blogTask.lastSuccessful'), | |
blog: this.get('blogTask').perform() | |
}; | |
}, | |
blogTask: task(function *(){ | |
yield timeout(1000); | |
let blog = {title: "This is a great Blog Post!"}; | |
console.log(blog); | |
return blog; | |
}) | |
.keepLatest() | |
.cancelOn('deactivate') | |
}); |
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.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