Skip to content

Instantly share code, notes, and snippets.

@asalant
Created November 10, 2016 21:51
Show Gist options
  • Save asalant/de82fb53028d85ca7a290fd672b63ae2 to your computer and use it in GitHub Desktop.
Save asalant/de82fb53028d85ca7a290fd672b63ae2 to your computer and use it in GitHub Desktop.
withSerializedSync = function(cls) {
var sync = cls.prototype.sync || Backbone.sync;
cls.prototype.sync = function() {
var args = arguments.length ? Array.prototype.slice.call(arguments,0) : [];
if (!this._lastSync) {
this._lastSync = sync.apply(this, args);
} else {
var _this = this;
this._lastSync = this._lastSync.then(function() {
return sync.apply(_this, args);
});
}
return this._lastSync;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment