Created
March 28, 2012 23:02
-
-
Save krusty/2231337 to your computer and use it in GitHub Desktop.
Backbone setTimeout callbacks
This file contains hidden or 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
fetch: function (options) { | |
this.trigger('fetching'); | |
Backbone.Model.prototype.fetch.call( | |
this, | |
smb.wrap_callbacks(this, options) | |
); | |
}, |
This file contains hidden or 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
wrap_callbacks: function (that, options) { | |
var new_options = _.clone(options) || {}; | |
new_options.success = function (object, response) { | |
if (options && typeof options.success === "function") { | |
options.success.call(arguments); | |
} | |
if (response.pending) { | |
object.trigger('partial'); | |
setTimeout(_.bind(object.refresh, object), 2000); | |
} | |
that.trigger('done'); | |
}; | |
new_options.error = function (object, response) { | |
if (options && typeof options.error === "function") { | |
options.error.call(arguments); | |
} | |
smb.flash_error(response); | |
that.trigger('done'); | |
}; | |
return new_options; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment