Skip to content

Commit

Permalink
refactor: remove legacy code for IE in ajax
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `ajax` no longer supports IE
  • Loading branch information
demensky committed Feb 22, 2023
1 parent 7d3c4ec commit 4fc4890
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 106 deletions.
45 changes: 0 additions & 45 deletions spec/observables/dom/ajax-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,37 +330,6 @@ describe('ajax', () => {
expect(complete).to.be.true;
});

it('should fail if fails to parse response in older IE', () => {
let error: any;
const obj: AjaxConfig = {
url: '/flibbertyJibbet',
method: '',
};

// No `response` property on the object (for older IE).
MockXMLHttpRequest.noResponseProp = true;

ajax(obj).subscribe({
next: () => {
throw new Error('should not next');
},
error: (err: any) => {
error = err;
},
complete: () => {
throw new Error('should not complete');
},
});

MockXMLHttpRequest.mostRecent.respondWith({
status: 207,
responseText: 'Wee! I am text, but should be valid JSON!',
});

expect(error instanceof SyntaxError).to.be.true;
expect(error.message).to.equal('Unexpected token W in JSON at position 0');
});

it('should fail on 404', () => {
let error: any;
const obj: AjaxConfig = {
Expand Down Expand Up @@ -1583,11 +1552,6 @@ class MockXHREventTarget {
class MockXMLHttpRequest extends MockXHREventTarget {
static readonly DONE = 4;

/**
* Set to `true` to test IE code paths.
*/
static noResponseProp = false;

private static requests: Array<MockXMLHttpRequest> = [];
private static recentRequest: MockXMLHttpRequest;

Expand All @@ -1600,7 +1564,6 @@ class MockXMLHttpRequest extends MockXHREventTarget {
}

static clearRequest(): void {
MockXMLHttpRequest.noResponseProp = false;
MockXMLHttpRequest.requests.length = 0;
MockXMLHttpRequest.recentRequest = null!;
}
Expand Down Expand Up @@ -1639,9 +1602,6 @@ class MockXMLHttpRequest extends MockXHREventTarget {
super();
MockXMLHttpRequest.recentRequest = this;
MockXMLHttpRequest.requests.push(this);
if (MockXMLHttpRequest.noResponseProp) {
delete this['response'];
}
}

// @ts-ignore: Property has no initializer and is not definitely assigned
Expand Down Expand Up @@ -1755,11 +1715,6 @@ class MockXMLHttpRequest extends MockXHREventTarget {
break;
}

// We're testing old IE, forget all of that response property stuff.
if (MockXMLHttpRequest.noResponseProp) {
delete this['response'];
}

this.triggerEvent('load', { type: 'load', total: response.total ?? 0, loaded: response.loaded ?? 0 });
this.triggerEvent('readystatechange', { type: 'readystatechange' });
}
Expand Down
3 changes: 1 addition & 2 deletions src/internal/ajax/AjaxResponse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AjaxRequest, AjaxResponseType } from './types';
import { getXHRResponse } from './getXHRResponse';

/**
* A normalized response from an AJAX request. To get the data from the response,
Expand Down Expand Up @@ -116,7 +115,7 @@ export class AjaxResponse<T> {
}, {})
: {};

this.response = getXHRResponse(xhr);
this.response = xhr.response;
const { loaded, total } = originalEvent;
this.loaded = loaded;
this.total = total;
Expand Down
13 changes: 1 addition & 12 deletions src/internal/ajax/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,18 +481,7 @@ export function fromAjax<T>(init: AjaxConfig): Observable<AjaxResponse<T>> {
if (status < 400) {
progressSubscriber?.complete?.();

let response: AjaxResponse<T>;
try {
// This can throw in IE, because we end up needing to do a JSON.parse
// of the response in some cases to produce object we'd expect from
// modern browsers.
response = createResponse(DOWNLOAD, event);
} catch (err) {
destination.error(err);
return;
}

destination.next(response);
destination.next(createResponse(DOWNLOAD, event));
destination.complete();
} else {
progressSubscriber?.error?.(event);
Expand Down
11 changes: 1 addition & 10 deletions src/internal/ajax/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AjaxRequest } from './types';
import { getXHRResponse } from './getXHRResponse';
import { createErrorClass } from '../util/createErrorClass';

/**
Expand Down Expand Up @@ -63,15 +62,7 @@ export const AjaxError: AjaxErrorCtor = createErrorClass(
this.request = request;
this.status = xhr.status;
this.responseType = xhr.responseType;
let response: any;
try {
// This can throw in IE, because we have to do a JSON.parse of
// the response in some cases to get the expected response property.
response = getXHRResponse(xhr);
} catch (err) {
response = xhr.responseText;
}
this.response = response;
this.response = xhr.response;
}
);

Expand Down
37 changes: 0 additions & 37 deletions src/internal/ajax/getXHRResponse.ts

This file was deleted.

0 comments on commit 4fc4890

Please sign in to comment.