nytimes / backbone.trackit

Manage unsaved changes in a Backbone Model.
202 stars 33 forks source link

Add Support for Deep Models #19

Open js62789 opened 9 years ago

js62789 commented 9 years ago

Trackit currently uses underscore's clone method to set original attributes, which is a shallow clone and not a deep clone. As a result, changing nested attributes in a model will also change the attributes in model._originalAttrs. When calling model.unsavedAttributes(), a comparison of the original attributes and current attributes will indicate that there are no unsaved attributes.

This implementation adds a _cloneAttributes method to perform a deep clone on the original attributes for a more accurate comparison when calling unsavedAttributes. Unfortunately, underscore doesn't have a deep clone method and has repeatedly refused implementing one.