Created
February 24, 2012 23:45
-
-
Save trak3r/1904658 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
# saves are queued on a per-model-instance (aka "cid") basis... | |
Backbone.Model.prototype.saveWithoutQueue = Backbone.Model.prototype.save | |
Backbone.Model.prototype.save = (key, value, options) -> | |
if _.isObject(key) or not key? # flip 'em | |
options = value | |
value = null | |
options = (if options then _.clone(options) else {}) | |
success = options.success | |
options.success = (model, resp) -> | |
success model, resp if success | |
if 0 is jQuery(document).queue(model.cid).length | |
# we were the last ones | |
model.queueHasBeenStarted = false | |
else | |
# run the next one in the queue | |
jQuery(document).dequeue model.cid | |
error = options.error | |
options.error = (model, resp) -> | |
error model, resp if error | |
if 0 is jQuery(document).queue(model.cid).length | |
# we were the last ones | |
model.queueHasBeenStarted = false | |
else | |
# run the next one in the queue | |
jQuery(document).dequeue model.cid | |
if _.isObject(key) or not key? # flip 'em back | |
value = options | |
options = null | |
jQuery(document).queue @cid, _.bind(-> | |
@saveWithoutQueue key, value, options | |
, this) | |
unless @queueHasBeenStarted | |
@queueHasBeenStarted = true | |
jQuery(document).dequeue @cid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment