Skip to content

Instantly share code, notes, and snippets.

@trmcnvn
Created December 22, 2016 10:44
Show Gist options
  • Save trmcnvn/00e7d68c7d16a7ec5cafc64ea92c6176 to your computer and use it in GitHub Desktop.
Save trmcnvn/00e7d68c7d16a7ec5cafc64ea92c6176 to your computer and use it in GitHub Desktop.
Cancel in-flight ember-data requests
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