Last active
August 13, 2018 19:35
-
-
Save alexmiddeleer/20f785e11d577a806031d55d32417e23 to your computer and use it in GitHub Desktop.
live records vs live arrays test
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'; | |
import { inject as service } from '@ember/service'; | |
export default Ember.Controller.extend({ | |
appName: 'Live Arrays and Vs Normal Arrays, both with Ember Data records', | |
store: service(), | |
init() { | |
let store = this.get('store'); | |
store.push({ | |
data: [{ | |
id: 1, | |
type: 'widget', | |
attributes: { | |
foo: 1 | |
}, | |
relationships: {} | |
}] | |
}); | |
this.set('widgets', store.peekAll('widget')); | |
this.set('widgets2', store.peekAll('widget').toArray()); | |
}, | |
actions: { | |
updateRecord() { | |
this.get('widgets.firstObject').set('foo', Math.floor(Math.random() * 10)); | |
}, | |
addRecord() { | |
let store = this.get('store'); | |
store.push({ | |
data: [{ | |
id: Math.random(), | |
type: 'widget', | |
attributes: { | |
foo: Math.floor(Math.random() * 10) | |
}, | |
relationships: {} | |
}] | |
}); | |
} | |
} | |
}); |
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 Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
export default Model.extend({ | |
foo: attr() | |
}); |
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.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-data": "3.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment