cartodb-4.42/lib/assets/javascripts/dashboard/data/backbone/sync-abort.js
2024-04-06 05:25:13 +00:00

24 lines
522 B
JavaScript

var Backbone = require('backbone');
/**
* Custom sync method to only allow a single request at a time,
* any prev ongoing request at a time of a sync call will be aborted.
*
* @example
* var MyModel = Backbone.Model.extend({
* // …
* sync: syncAbort,
*/
module.exports = function (method, self, opts) {
if (this._xhr) {
this._xhr.abort();
}
var xhr = this._xhr = Backbone.Model.prototype.sync.apply(this, arguments);
xhr.always(function () {
self._xhr = null;
});
return xhr;
};