Last active
August 29, 2018 15:27
-
-
Save Kilowhisky/9d09b6673cb026a0303bab0d1bbc6f0a to your computer and use it in GitHub Desktop.
Reload Record Hell
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'; | |
import Ember from 'ember'; | |
export default DS.RESTAdapter.extend({ | |
namespace: 'api' | |
}); |
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({ | |
appName: 'Ember Twiddle' | |
}); |
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 Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
people: hasMany('person'), | |
name: attr('string') | |
}); |
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({ | |
name: attr('string') | |
}); |
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 { hash } from 'rsvp'; | |
export default Ember.Route.extend({ | |
init(){ | |
$.mockjax({ url: '/api/contracts/1', responseText: { id: '1', name: 'contract 1', people: [] }}); | |
$.mockjax({ | |
url: '/api/people', | |
responseText: [ | |
{ id: '1', name: 'tom' }, | |
{ id: '2', name: 'mary' }, | |
{ id: '3', name: 'dale' } | |
] | |
}); | |
}, | |
model(){ | |
return hash({ | |
contract: this.store.findRecord('contract', '1'), | |
people: this.store.findAll('person') | |
}); | |
}, | |
actions: { | |
reload(contract, people){ | |
contract.reload(); | |
people.update(); | |
}, | |
rollback(contract){ | |
contract.rollbackAttributes(); | |
}, | |
force(contract){ | |
contract.hasMany('people').push([]); | |
}, | |
associate(person, contract){ | |
contract.people.addObject(person); | |
}, | |
allTheThings(model){ | |
model.contract.unloadRecord(); | |
this.store.unloadAll('people'); | |
this.refresh(); | |
} | |
} | |
}); |
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'; | |
import Ember from 'ember'; | |
export default DS.JSONSerializer.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
{ | |
"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": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2", | |
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js" | |
}, | |
"addons": { | |
"ember-data": "3.2.0", | |
"ember-power-select": "2.0.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment