Skip to content

Instantly share code, notes, and snippets.

@krusty
Created March 28, 2012 23:02
Show Gist options
  • Save krusty/2231337 to your computer and use it in GitHub Desktop.
Save krusty/2231337 to your computer and use it in GitHub Desktop.
Backbone setTimeout callbacks
fetch: function (options) {
this.trigger('fetching');
Backbone.Model.prototype.fetch.call(
this,
smb.wrap_callbacks(this, options)
);
},
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