cartodb-4.29/lib/assets/javascripts/dashboard/data/backbone/sync-abort.js
2020-06-15 10:58:47 +08: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;
};