Last active
July 11, 2017 20:01
-
-
Save hjdivad/7f94a0e81ea38d9022a5007ef8be15c8 to your computer and use it in GitHub Desktop.
set -> destroy -> unload semantics
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 DS from 'ember-data'; | |
const { RSVP: { resolve }} = Ember; | |
export default DS.Adapter.extend({ | |
deleteRecord() { | |
return resolve(null); | |
} | |
}); |
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 Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
author: belongsTo('author', { inverse: null, async: false }), | |
name: 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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
let payload = { | |
data: { | |
id: 1, | |
type: 'book', | |
attributes: { | |
name: 'History of the Decline and Fall of the Roman Empire', | |
}, | |
relationships: { | |
author: { | |
data: { | |
id: 2, | |
type: 'author', | |
} | |
} | |
} | |
}, | |
included: [{ | |
id: 2, | |
type: 'author', | |
attributes: { | |
name: 'Edward Gibbon' | |
}, | |
}, { | |
id: 3, | |
type: 'author', | |
attributes: { | |
name: 'David J. Hamilton', | |
}, | |
}] | |
}; | |
let store = this.get('store'); | |
store.push(payload); | |
return store.peekRecord('book', 1); | |
}, | |
actions: { | |
setNewAuthor() { | |
let store = this.get('store'); | |
let david = store.peekRecord('author', 3); | |
let book = store.peekRecord('book', 1); | |
book.set('author', david); | |
}, | |
destroyNewAuthor() { | |
let store = this.get('store'); | |
let david = store.peekRecord('author', 3); | |
david.destroyRecord(); | |
}, | |
unloadNewAuthor() { | |
let store = this.get('store'); | |
let david = store.peekRecord('author', 3); | |
david.unloadRecord(); | |
} | |
}, | |
}); |
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": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment