Rollback deletion to handle server error in Ember.js

We have an Ember.js application that uses Ember data. We are trying to do the following:

  • Delete entry.
  • If a server error occurs (due to the fact that the application may have a “locked” state, when the records cannot be deleted), flip the record to the previous state, suggest the user to unlock the application and continue.
  • If there is no server error, continue as usual.

We found that this does not work.

object.destroyRecord().then ->
  # handle success
, (reason)->
  object.rollback()
  # prompt for the unlock

In both cases, we see an error that looks like this:

Error: Assertion Failed: calling set on destroyed object

But it is unclear how to remove the state isDestroyedafter installing it.

, , , destroyRecord, , .

+4
2

, getError().

// Overwrite default destroyRecord
destroyRecord: function () {
    this.deleteRecord();
    this.save().then(
        function (){
            //Success
        },
        function () {
            //Failure
        }
    );
},

becameError: function (item) {
    this.rollback();
}

, , .

0

deleteRecord, . , .

  object.deleteRecord()
  object.save().then( ->
     # handle success
  , (reason) ->
     object.rollback()
  )
+1

Source: https://habr.com/ru/post/1534397/


All Articles