Skip to content

Commit

Permalink
refactor: Use readyState instead of the done boolean.
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Sep 2, 2020
1 parent 37a8d3c commit 2f95d73
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/internal/ajax/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ export const ajax: AjaxCreationMethod = (() => {

export function fromAjax<T>(config: AjaxConfig): Observable<AjaxResponse<T>> {
return new Observable<AjaxResponse<T>>((destination) => {
let done = false;

// Normalize the headers. We're going to make them all lowercase, since
// Headers are case insenstive by design. This makes it easier to verify
// that we aren't setting or sending duplicates.
Expand Down Expand Up @@ -368,7 +366,6 @@ export function fromAjax<T>(config: AjaxConfig): Observable<AjaxResponse<T>> {
if (xhr.status < 400) {
progressSubscriber?.complete?.();

done = true;
let response: AjaxResponse<T>;
try {
// This can throw in IE, because we end up needing to do a JSON.parse
Expand Down Expand Up @@ -424,7 +421,7 @@ export function fromAjax<T>(config: AjaxConfig): Observable<AjaxResponse<T>> {
}

return () => {
if (!done && xhr) {
if (xhr && xhr.readyState !== 4 /*XHR done*/) {
xhr.abort();
}
};
Expand Down

0 comments on commit 2f95d73

Please sign in to comment.