Last active
October 5, 2016 10:55
-
-
Save pangratz/9019e034392dc2e61aea to your computer and use it in GitHub Desktop.
ds-references
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({ | |
| actions: { | |
| loadFamily: function() { | |
| var personRef = this.store.getReference('person', 1); | |
| var person = personRef.value(); | |
| var familyRef = person.belongsTo('family'); | |
| if (!familyRef.value()) { | |
| familyRef.load().then((family) => { | |
| this.set('model.family', family); | |
| }); | |
| } | |
| } | |
| } | |
| }); |
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 { server, json } from '../initializers/pretender'; | |
| server.map(function() { | |
| this.get('/people/1', function() { | |
| return json({ | |
| data: { | |
| type: 'person', | |
| id: 1, | |
| attributes: { | |
| name: 'George Michael Bluth' | |
| }, | |
| relationships: { | |
| family: { | |
| data: { | |
| type: 'family', | |
| id: 1 | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| }); | |
| this.get('/families/1', function() { | |
| return json({ | |
| data: { | |
| type: 'family', | |
| id: 1, | |
| attributes: { | |
| name: "Bluths" | |
| } | |
| } | |
| }); | |
| }); | |
| }); | |
| export default Ember.Route.extend({ | |
| model: function() { | |
| return Ember.RSVP.hash({ | |
| person: this.store.findRecord('person', 1) | |
| }); | |
| }, | |
| actions: { | |
| reload: function() { | |
| var personRef = this.store.getReference('person', 1); | |
| personRef.reload(); | |
| } | |
| } | |
| }); |
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
| export function returnJSON(status, body) { | |
| return json(...arguments); | |
| }; | |
| export function json(status, body) { | |
| if (arguments.length === 1) { | |
| body = status; | |
| status = 200; | |
| } | |
| return [ | |
| status, | |
| { "Content-Type": "application/json" }, | |
| JSON.stringify(body) | |
| ]; | |
| }; | |
| export const server = new Pretender(); | |
| export function initialize() { | |
| }; | |
| export default { | |
| name: 'pretender', | |
| initialize | |
| }; |
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 DS from 'ember-data'; | |
| const { attr, hasMany } = DS; | |
| export default DS.Model.extend({ | |
| persons: hasMany(), | |
| name: attr() | |
| }); |
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 DS from 'ember-data'; | |
| const { attr, belongsTo } = DS; | |
| export default DS.Model.extend({ | |
| name: attr(), | |
| family: belongsTo() | |
| }); |
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.4.17", | |
| "EmberENV": { | |
| "FEATURES": { | |
| "ds-references": true | |
| } | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "canary", | |
| "ember-data": "canary", | |
| "ember-template-compiler": "canary", | |
| "route-recognizer": "https://rawgit.com/tildeio/route-recognizer/56f5fcec6ae58d8e86b5dc77609809fb91198142/dist/route-recognizer.js", | |
| "FakeXMLHttpRequest": "https://rawgit.com/pretenderjs/FakeXMLHttpRequest/23c3a96b5b24f1bfe595867437e4f128a29c2840/fake_xml_http_request.js", | |
| "pretender": "https://rawgit.com/pretenderjs/pretender/f52b8063665420a244ca4547e3eb57b09e61acf7/pretender.js" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment