Created
December 22, 2016 10:44
-
-
Save trmcnvn/00e7d68c7d16a7ec5cafc64ea92c6176 to your computer and use it in GitHub Desktop.
Cancel in-flight ember-data requests
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
export default JSONAPIAdapter.extend({ | |
init() { | |
this._super(...arguments); | |
this.xhrRequests = []; | |
}, | |
ajaxOptions() { | |
const options = this._super(...arguments); | |
const defaultBeforeSend = options.beforeSend; | |
options.beforeSend = function(xhr) { | |
defaultBeforeSend(xhr); | |
this.xhrRequests.addObject(xhr); | |
xhr.always(() => this.xhrRequests.removeObject(xhr)); | |
}; | |
return options; | |
}, | |
cancelRequests() { | |
this.xhrRequests.forEach(xhr => xhr.abort()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment