Skip to content

Instantly share code, notes, and snippets.

@aghecht
Created April 25, 2014 21:05
Show Gist options
  • Save aghecht/11303257 to your computer and use it in GitHub Desktop.
Save aghecht/11303257 to your computer and use it in GitHub Desktop.
(function() {
var get = Ember.get;
var set = Ember.set;
// Version of deleteRecord where clearRelationships() isn't called
var deleteRecord = function(record) {
record.transitionTo('deleted.uncommitted');
};
// Perform some state machine surgery
DS.RootState.loaded.saved.deleteRecord = deleteRecord;
DS.Model.reopen({
deleteRecord: function() {
this._savedStateName = this.get('currentState.stateName').substr(5);
this._super();
},
adapterDidInvalidate: function(errors) {
if (this.get('currentState.stateName') == 'root.deleted.inFlight') {
this.transitionTo(this._savedStateName);
}
this._super(errors);
}
});
DS.Store.reopen({
didSaveRecord: function(record, data) {
// Wait to clear the relationships until after the server gives the ok
if (record.get('currentState.stateName') == 'root.deleted.uncommitted') {
record.clearRelationships();
}
this._super(record, data);
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment