Last active
October 5, 2018 16:34
-
-
Save runspired/68ad36b99367946a32c470fe1504d0ee to your computer and use it in GitHub Desktop.
Ember Data - Local Deletion
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 Adapter from 'ember-data/adapters/json-api'; | |
import { resolve } from 'rsvp'; | |
export default class ApplicationAdapter extends Adapter { | |
deleteRecord(store, ModelClass, snapshot) { | |
if (snapshot.adapterOptions && snapshot.adapterOptions.isLocalDelete === true) { | |
return resolve({ data: null }); | |
} | |
return this._super(...arguments); | |
} | |
} |
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'; | |
let id = 123; | |
export default Ember.Controller.extend({ | |
people: Ember.A(), | |
actions: { | |
createPerson(name) { | |
let store = this.get('store'); | |
let person = store.push({ | |
data: { | |
type: 'person', | |
id: `${id++}`, | |
attributes: { name } | |
} | |
}); | |
this.get('people').addObject(person); | |
this.set('newPersonName', ''); | |
}, | |
deletePerson(person) { | |
this.get('people').removeObject(person); | |
person.destroyRecord({ | |
adapterOptions: { | |
isLocalDelete: true | |
} | |
}); | |
} | |
} | |
}); |
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'; | |
export default Model.extend({ | |
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 Serializer from 'ember-data/serializers/json-api'; | |
export default Serializer.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.13.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.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment