Skip to content

Instantly share code, notes, and snippets.

@lgsunnyvale
Forked from fearphage/gist:1902781
Created December 7, 2012 11:32
Show Gist options
  • Save lgsunnyvale/4232713 to your computer and use it in GitHub Desktop.
Save lgsunnyvale/4232713 to your computer and use it in GitHub Desktop.
Revert Backbone 0.9.1 from optimistic to realistic (read: classic) functionality
(function(CollectionPrototype, ModelPrototype, slice) {
var monkeyPatch = function(prototype, name) {
var method = prototype[name];
prototype[name] = function() {
var
args = slice.call(arguments)
,length = args.length
,options = length && length >= method.length && args[args.length - 1]
;
if (options && _.isObject(options) && !('wait' in options)) {
options.wait = true;
args.splice(-1, 1, options);
}
return method.apply(this, args);
};
};
_.each(['create', 'destroy', 'save'], function(name) {
monkeyPatch(ModelPrototype, name);
});
monkeyPatch(CollectionPrototype, 'create');
})(Backbone.Collection.prototype, Backbone.Model.prototype, [].slice);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment