Created
April 25, 2014 21:05
-
-
Save aghecht/11303257 to your computer and use it in GitHub Desktop.
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
(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