-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dirty checking on patch? #35
Comments
The There are 2 easy options to run dirty checking:
if (!this.model.hasChanged()) {
return console.log('Nothing to update');
}
this.model.save(this.model.changedAttributes()), {patch:true));
//..
initialize: function() {
this.originalModel = this.model.clone();
}
//...
onSave: function() {
var changedAttrs = this.model.changedAttributes(this.originalModel.toJSON());
if (!changedAttrs || !_.size(changedAttrs)) {
return console.log('Nothing to update');
}
this.model.save(changedAttrs, {patch:true));
//...
} Another option is to integrate a plugin that tracks changes since the last save, something like this one: I tend to agree it's a lot of work to do a pretty common task |
This is something that needs to be resolved on |
Is ampersand trying to improve where backbone fails or is it set on keeping failure parity? |
Well played :) We're talking about a reasonable feature here, but a feature for ampersand-model. The usecase might not be that common to add substantial code to ampersand-model, so IMHO the best solution would be another small requireable module that'd add the functionality to models. Totally doable. |
Also @pgilad it doesn't seem like ampersand models have a .clone fn, just FYI |
it seems a little weird that you have to specify which fields go up when you save a model and want to patch only what has changed
Currently this will send the entire model:
this will send the attributes that changed, but we have to manually specify the keys and values:
which is just as bad as not even using the model
The text was updated successfully, but these errors were encountered: