Ember Data - rollback on transition from form

My application has new / edit forms for a set of objects read from the backend.

When I open such a form and fill in / edit some fields and then delete, the entries appear in the lists of entities, although I did not make these changes. The problem of restarting the application (which reloads data from the backend) resolves the problem, but is not an option.

I tried to perform some transaction rollbacks in the willDestroyElement form view, but this seems fundamentally wrong, as it is called even after the successful form is submitted (and actually crashes with Attempted to handle event rollback on X while in state rootState.loaded.updated.inFlight ).

How would I ignore any unexpected form changes (similar to clicking the Cancel button that rolls back the transaction) for any use case that involves moving from forms?

Using Ember rc5, Ember Data 0.13.

+4
source share
1 answer

When exiting the form route, check the recording status. If its (isNew OR isDirty) and its NOT isSaving, rollback:

 App.FormRoute = Ember.Route.extend({ deactivate: function() { var model = this.controllerFor('form'); if ( (model.get('isNew') || model.get('isDirty')) && (!model.get('isSaving')) ) { model.rollback(); } } }); 
+4
source

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


All Articles