Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I ignore dirty records when refreshing a list from the server?

Using latest ember and ember-data.

I have a single-page application with a list of items, and the ability to open the items in tabs. I can edit the items in the open tabs, and without commiting the dirty record, go back to the list.

If I refresh the list, I get the error:

Error: Attempted to handle event loadedData on <> while in state rootState.loaded.updated.uncommitted

This is of course because I have done a App.TestObject.find() in the list, and still have the dirty uncommitted records (opened and edited records in tabs).

My goal is to show the list with updated records, but do nothing with the uncommited records. I do not want to do a rollback on the uncommited records. Is there a best practice for this?

This is a similar question, but I do not want the records reverted to original state. This is a similar case with a fiddle, but here the rollback is the right solution.

How can I solve the fiddle if I wanted to ignore the uncommitted records when I go back to the list?

like image 342
Christian Johannessen Avatar asked Apr 04 '13 06:04

Christian Johannessen


1 Answers

I only have a workaround for this issue by monkey-patching DS.Model.

DS.Model.reopen({
  loadedData: function() {
    if (this.get('isDirty') === false) {
      this._super.apply(this, arguments);
    }
  }
});

Resulting the model to not to update itself when in dirty state, no matter what's in the new JSON regarding this record. The other records will update themselves just fine.

like image 190
zeppelin Avatar answered Sep 29 '22 14:09

zeppelin