Limits of Backbone.Model.previousAttributes for Rolling Back a Failed save()
0 reputation · 26 Jun 2021, 12:13 UTC
Rollback goal
I want to restore a Backbone model's client-side state after model.save() fails, using the documented previousAttributes() snapshot and the model's error event. The intent is a clean revert without triggering view re-renders, so the plan is to reapply the snapshot with the silent option.
Constraints and uncertainty
The model holds nested objects and arrays as attribute values. My understanding is that previousAttributes() returns a shallow snapshot, so nested references may already reflect the failed edits, making the revert incomplete. I am also unsure how far back the snapshot reaches: whether it reflects state before the last set or before the last successful sync, and how multiple unsaved changes interact with it.
Assume Backbone 1.x. Server-side effects of a partially processed request are out of scope; the concern is only local attribute consistency.
Questions
- Does
previousAttributes()capture state from the lastsetcall or the last successfulsave, and what happens across several unsaved mutations? - Is a manual deep copy before
save()the only reliable way to roll back nested attributes? - Does reapplying the snapshot with
{silent: true}fully suppresschangeevents, or are there edge cases?