Created
June 3, 2012 10:30
-
-
Save aligo/2862960 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
save_changes_common = | |
sync: (method, model, options) -> | |
if method == 'update' && model.changedAttributes() | |
options.data = JSON.stringify(model.changedAttributes()) | |
options.contentType = 'application/json'; | |
Backbone.sync.call(this, method, model, options) | |
save_changes_model = | |
saveChanges: (key, value, options) -> | |
self = this | |
if _.isObject(key) || key == null | |
attrs = key | |
options = value | |
else | |
attrs = {} | |
attrs[key] = value | |
`options = options ? _.clone(options) : {}` | |
_.extend options, { wait: true } | |
actually_changed = _.any attrs, (value, key)-> | |
value != self.get key | |
if actually_changed | |
@save attrs, options | |
@set attrs | |
_.extend Backbone.Model.prototype, save_changes_common, save_changes_model | |
_.extend Backbone.Collection.prototype, save_changes_common |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment