Skip to content

Instantly share code, notes, and snippets.

@hjdivad
Created February 22, 2018 22:09
Show Gist options
  • Save hjdivad/e22b290daeaa0a52784fbb496e6c9458 to your computer and use it in GitHub Desktop.
Save hjdivad/e22b290daeaa0a52784fbb496e6c9458 to your computer and use it in GitHub Desktop.
DOM delete
import Ember from 'ember';
export default Ember.Object.extend({
deleteRecord(store, modelClass, snapshot) {
return Ember.RSVP.resolve();
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
destroyBook(book) {
book.destroyRecord();
},
deleteBook(book) {
book.deleteRecord();
},
destroyObject(obj) {
obj.destroy();
}
},
});
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(),
});
import Ember from 'ember';
export default Ember.Route.extend({
store: Ember.inject.service('store'),
model() {
this.get('store').push({
data: {
id: 1,
type: 'book',
attributes: {
name: 'The History of the Decline and Fall of the Roman Empire'
}
}
});
return this.get('store').peekRecord('book', 1);
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
Ze book: {{model.name}}<br />
isDeleted: {{model.isDeleted}}<br />
isDestroyed: {{model.isDestroyed}}<br />
stateName: {{model.currentState.stateName}}<br/>
<div>
<button {{action 'deleteBook' model}}>delete</button>
<button {{action 'destroyBook' model}}>destroyRecord</button>
<button {{action 'destroyObject' model}}>destroy</button>
</div>
{
"version": "0.13.0",
"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