From 2f95d73fa8f01fc1201755f635bfdd34d841d04c Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Wed, 2 Sep 2020 15:38:24 -0500 Subject: [PATCH] refactor: Use readyState instead of the `done` boolean. Addresses comments here: https://github.com/ReactiveX/rxjs/pull/5661\#discussion_r481786685 --- src/internal/ajax/ajax.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/internal/ajax/ajax.ts b/src/internal/ajax/ajax.ts index e435d2faba..7f32bf38e9 100644 --- a/src/internal/ajax/ajax.ts +++ b/src/internal/ajax/ajax.ts @@ -271,8 +271,6 @@ export const ajax: AjaxCreationMethod = (() => { export function fromAjax(config: AjaxConfig): Observable> { return new Observable>((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. @@ -368,7 +366,6 @@ export function fromAjax(config: AjaxConfig): Observable> { if (xhr.status < 400) { progressSubscriber?.complete?.(); - done = true; let response: AjaxResponse; try { // This can throw in IE, because we end up needing to do a JSON.parse @@ -424,7 +421,7 @@ export function fromAjax(config: AjaxConfig): Observable> { } return () => { - if (!done && xhr) { + if (xhr && xhr.readyState !== 4 /*XHR done*/) { xhr.abort(); } };