Last active
October 13, 2017 02:32
-
-
Save jacobq/2f0db50ac3afb8dd01c11ab0345f010f to your computer and use it in GitHub Desktop.
Data Relationships
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 LSAdapter from 'ember-localstorage-adapter'; | |
| export default LSAdapter.extend({ | |
| namespace: 'twiddleApp' | |
| }); |
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.Component.extend({ | |
| tagName: 'select' | |
| }); |
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: 'Data relationship demo' | |
| }); |
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 RSVP from 'rsvp'; | |
| export function initialize(appInstance) { | |
| const store = appInstance.lookup('service:store'); | |
| //console.log('DEBUG: creating initial store entries'); | |
| const promises = []; | |
| // Leak the store for debugging / testing | |
| window.debug = { | |
| store | |
| }; | |
| // Roles | |
| let camera = store.createRecord('role', { | |
| name: 'Camera', | |
| }) | |
| // Drivers | |
| let usbCamera = store.createRecord('driver', { | |
| name: 'USB camera', | |
| roles: [ camera ] | |
| }) | |
| promises.push(usbCamera.save()); | |
| let networkCamera = store.createRecord('driver', { | |
| name: 'Network camera', | |
| roles: [ camera ] | |
| }) | |
| promises.push(networkCamera.save()); | |
| camera.set('drivers', [ usbCamera, networkCamera ]); | |
| promises.push(camera.save()); | |
| // Devices | |
| let device = store.createRecord('device', { | |
| name: 'Camera 1', | |
| driver: usbCamera | |
| }) | |
| promises.push(device.save()); | |
| device = store.createRecord('device', { | |
| name: 'Camera 2', | |
| driver: usbCamera | |
| }) | |
| promises.push(device.save()); | |
| device = store.createRecord('device', { | |
| name: 'Camera 3', | |
| driver: networkCamera | |
| }) | |
| promises.push(device.save()); | |
| return RSVP.all(promises); | |
| } | |
| export default { | |
| name: 'create-store-entries', | |
| after: 'ember-data', | |
| 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 Model from "ember-data/model"; | |
| import attr from "ember-data/attr"; | |
| import { belongsTo, hasMany } from "ember-data/relationships"; | |
| export default Model.extend({ | |
| name: attr('string'), | |
| driver: belongsTo('driver'), | |
| }); |
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 Model from "ember-data/model"; | |
| import attr from "ember-data/attr"; | |
| import { belongsTo, hasMany } from "ember-data/relationships"; | |
| export default Model.extend({ | |
| name: attr('string'), | |
| devices: hasMany('device'), | |
| roles: hasMany('role'), | |
| }); |
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 Model from "ember-data/model"; | |
| import attr from "ember-data/attr"; | |
| import { belongsTo, hasMany } from "ember-data/relationships"; | |
| export default Model.extend({ | |
| name: attr('string'), | |
| driver: belongsTo('driver') | |
| }); |
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 RSVP from 'rsvp'; | |
| export default Ember.Route.extend({ | |
| model() { | |
| return RSVP.hash({ | |
| roles: this.get('store').findAll('role'), | |
| devices: this.get('store').findAll('device'), | |
| drivers: this.get('store').findAll('driver') | |
| }) | |
| } | |
| }); |
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 { LSSerializer } from 'ember-localstorage-adapter'; | |
| export default LSSerializer.extend(); |
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 function destroyApp(application) { | |
| Ember.run(application, 'destroy'); | |
| } |
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 Resolver from '../../resolver'; | |
| import config from '../../config/environment'; | |
| const resolver = Resolver.create(); | |
| resolver.namespace = { | |
| modulePrefix: config.modulePrefix, | |
| podModulePrefix: config.podModulePrefix | |
| }; | |
| export default resolver; |
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 Application from '../../app'; | |
| import config from '../../config/environment'; | |
| const { run } = Ember; | |
| const assign = Ember.assign || Ember.merge; | |
| export default function startApp(attrs) { | |
| let application; | |
| let attributes = assign({rootElement: "#test-root"}, config.APP); | |
| attributes = assign(attributes, attrs); // use defaults, but you can override; | |
| run(() => { | |
| application = Application.create(attributes); | |
| application.setupForTesting(); | |
| application.injectTestHelpers(); | |
| }); | |
| return application; | |
| } |
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 resolver from './helpers/resolver'; | |
| import { | |
| setResolver | |
| } from 'ember-qunit'; | |
| setResolver(resolver); |
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-localstorage-adapter": "1.0.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment