Created
June 15, 2016 15:48
-
-
Save zkwentz/2702f93cac6ad45a4d00e23b56e4165e to your computer and use it in GitHub Desktop.
2. Promises in Computed Properties
This file contains 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 DS from 'ember-data'; | |
export default DS.FixtureAdapter.extend({}); |
This file contains 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('model.comments.[]',function() { | |
return this.get('model.comments').then(function(_this){ | |
return function(comments) { | |
return comments; | |
}; | |
}(this)); | |
}), | |
}); |
This file contains 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 DS from "ember-data"; | |
var Comment = DS.Model.extend({ | |
body: DS.attr('string'), | |
author: DS.attr('string'), | |
post: DS.belongsTo('post',{async:true}), | |
commentType: DS.belongsTo('commentType',{async:true}) | |
}); | |
Comment.reopenClass({ | |
FIXTURES: [ | |
{ | |
id: 1, | |
author: "Zach Wentz", | |
post: 1, | |
commentType: 1, | |
body: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium aspernatur quam qui commodi beatae placeat ducimus aliquam veritatis ullam sed! Sit assumenda aspernatur sunt harum accusamus, repellat labore! Repellendus, corporis!" | |
}, | |
{ | |
id: 2, | |
author: "Ryan Christiani", | |
post: 1, | |
commentType: 1, | |
body: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium aspernatur quam qui commodi beatae placeat ducimus aliquam veritatis ullam sed! Sit assumenda aspernatur sunt harum accusamus, repellat labore! Repellendus, corporis!" | |
}, | |
{ | |
id: 3, | |
author: "Ryan Christiani", | |
post: 1, | |
commentType: 2, | |
body: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium aspernatur quam qui commodi beatae placeat ducimus aliquam veritatis ullam sed! Sit assumenda aspernatur sunt harum accusamus, repellat labore! Repellendus, corporis!" | |
} | |
] | |
}); | |
export default Comment; |
This file contains 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 DS from "ember-data"; | |
var Post = DS.Model.extend({ | |
title: DS.attr('string'), | |
body: DS.attr('string'), | |
author: DS.attr('string'), | |
sequence: DS.attr('number'), | |
comments: DS.hasMany('comment',{async:true}) | |
}); | |
Post.reopenClass({ | |
FIXTURES: [ | |
{ | |
id: 1, | |
title: "Using Ember CLI to create a Fixture Adapter.", | |
author: "Zach Wentz", | |
comments: [1,2,3], | |
sequence: 3, | |
body: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium aspernatur quam qui commodi beatae placeat ducimus aliquam veritatis ullam sed! Sit assumenda aspernatur sunt harum accusamus, repellat labore! Repellendus, corporis!" | |
}, | |
{ | |
id: 2, | |
title: "Ember is lots of fun", | |
author: "Ryan Christiani", | |
sequence: 1, | |
body: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium aspernatur quam qui commodi beatae placeat ducimus aliquam veritatis ullam sed! Sit assumenda aspernatur sunt harum accusamus, repellat labore! Repellendus, corporis!" | |
}, | |
{ | |
id: 3, | |
title: "Ember, Node, Express and You!", | |
author: "Ryan Christiani", | |
sequence: 2, | |
body: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium aspernatur quam qui commodi beatae placeat ducimus aliquam veritatis ullam sed! Sit assumenda aspernatur sunt harum accusamus, repellat labore! Repellendus, corporis!" | |
} | |
] | |
}); | |
export default Post; |
This file contains 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.Route.extend({ | |
store: Ember.inject.service(), | |
model() { | |
return this.store.find('post',1); | |
} | |
}); |
This file contains 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.9.2", | |
"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.6.0", | |
"ember-data": "1.13.15", | |
"ember-template-compiler": "2.6.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment