Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 80e6e15

Browse files
knownasilyaalexlafroscia
authored andcommitted
fix(deprecation): the new EmberObject is deprecated
This throws deprecation warnings in consuming apps.
1 parent bec4d2c commit 80e6e15

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

addon/raw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function raw<T = Response>(
1515
url: string,
1616
options?: AJAXOptions
1717
): AJAXPromise<RawResponse<T>> {
18-
const ajax = new AjaxRequest();
18+
const ajax = AjaxRequest.create();
1919

2020
return ajax.raw(url, options);
2121
}

addon/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function request<T = Response>(
1313
url: string,
1414
options?: AJAXOptions
1515
): AJAXPromise<T> {
16-
const ajax = new AjaxRequest();
16+
const ajax = AjaxRequest.create();
1717

1818
return ajax.request(url, options);
1919
}

tests/unit/mixins/ajax-request-test.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Unit | Mixin | ajax request', function() {
3535

3636
describe('options method', function() {
3737
it('sets raw data', function() {
38-
const service = new AjaxRequest();
38+
const service = AjaxRequest.create();
3939
const url = '/test';
4040
const type = 'GET';
4141
const ajaxOptions = service.options(url, {
@@ -56,7 +56,7 @@ describe('Unit | Mixin | ajax request', function() {
5656
});
5757

5858
it('sets options correctly', function() {
59-
const service = new AjaxRequest();
59+
const service = AjaxRequest.create();
6060
const url = '/test';
6161
const type = 'POST';
6262
const data = JSON.stringify({ key: 'value' });
@@ -77,7 +77,7 @@ describe('Unit | Mixin | ajax request', function() {
7777
});
7878

7979
it('does not modify the options object argument', function() {
80-
const service = new AjaxRequest();
80+
const service = AjaxRequest.create();
8181
const url = 'test';
8282
const data = JSON.stringify({ key: 'value' });
8383
const baseOptions = { type: 'POST', data };
@@ -86,7 +86,7 @@ describe('Unit | Mixin | ajax request', function() {
8686
});
8787

8888
it('does not override contentType when defined', function() {
89-
const service = new AjaxRequest();
89+
const service = AjaxRequest.create();
9090
const url = '/test';
9191
const type = 'POST';
9292
const data = JSON.stringify({ key: 'value' });
@@ -107,7 +107,7 @@ describe('Unit | Mixin | ajax request', function() {
107107
});
108108

109109
it('can handle empty data', function() {
110-
const service = new AjaxRequest();
110+
const service = AjaxRequest.create();
111111
const url = '/test';
112112
const type = 'POST';
113113
const ajaxOptions = service.options(url, { type });
@@ -293,7 +293,7 @@ describe('Unit | Mixin | ajax request', function() {
293293
});
294294

295295
it('can be set on a per-request basis', function() {
296-
const service = new AjaxRequest();
296+
const service = AjaxRequest.create();
297297

298298
expect(service.options('users/me', { namespace: '/api' }).url).to.equal(
299299
'/api/users/me'
@@ -317,7 +317,7 @@ describe('Unit | Mixin | ajax request', function() {
317317

318318
describe('type', function() {
319319
it('defaults to GET', function() {
320-
const service = new AjaxRequest();
320+
const service = AjaxRequest.create();
321321
const url = 'test';
322322
const ajaxOptions = service.options(url);
323323

@@ -341,7 +341,7 @@ describe('Unit | Mixin | ajax request', function() {
341341
});
342342

343343
it('request() promise label is correct', function() {
344-
const service = new AjaxRequest();
344+
const service = AjaxRequest.create();
345345
const url = '/posts';
346346
const data = {
347347
type: 'POST',
@@ -366,7 +366,7 @@ describe('Unit | Mixin | ajax request', function() {
366366
});
367367

368368
it('post() promise label is correct', function() {
369-
const service = new AjaxRequest();
369+
const service = AjaxRequest.create();
370370
const url = '/posts';
371371
const title = 'Title';
372372
const description = 'Some description.';
@@ -392,7 +392,7 @@ describe('Unit | Mixin | ajax request', function() {
392392
});
393393

394394
it('put() promise label is correct', function() {
395-
const service = new AjaxRequest();
395+
const service = AjaxRequest.create();
396396
const url = '/posts/1';
397397
const title = 'Title';
398398
const description = 'Some description.';
@@ -420,7 +420,7 @@ describe('Unit | Mixin | ajax request', function() {
420420
});
421421

422422
it('patch() promise label is correct', function() {
423-
const service = new AjaxRequest();
423+
const service = AjaxRequest.create();
424424
const url = '/posts/1';
425425
const description = 'Some description.';
426426
const options = {
@@ -446,7 +446,7 @@ describe('Unit | Mixin | ajax request', function() {
446446
});
447447

448448
it('del() promise label is correct', function() {
449-
const service = new AjaxRequest();
449+
const service = AjaxRequest.create();
450450
const url = '/posts/1';
451451
const serverResponse = [
452452
200,
@@ -465,7 +465,7 @@ describe('Unit | Mixin | ajax request', function() {
465465
});
466466

467467
it('delete() promise label is correct', function() {
468-
const service = new AjaxRequest();
468+
const service = AjaxRequest.create();
469469
const url = '/posts/1';
470470
const serverResponse = [
471471
200,
@@ -498,7 +498,7 @@ describe('Unit | Mixin | ajax request', function() {
498498
});
499499
this.server.post(url, () => serverResponse);
500500

501-
const service = new AjaxRequest();
501+
const service = AjaxRequest.create();
502502
const handleResponse = td.function('handle response');
503503
const expectedArguments = [
504504
anything(),
@@ -528,7 +528,7 @@ describe('Unit | Mixin | ajax request', function() {
528528
});
529529

530530
it('overrides host property in request config', function() {
531-
const service = new AjaxRequest();
531+
const service = AjaxRequest.create();
532532
const host = 'https://discuss.emberjs.com';
533533
const url = 'http://myurl.com/users/me';
534534
const ajaxOptions = service.options(url, { host });
@@ -700,7 +700,7 @@ describe('Unit | Mixin | ajax request', function() {
700700
];
701701
this.server.get('/posts', () => response);
702702

703-
const service = new AjaxRequest();
703+
const service = AjaxRequest.create();
704704
return service
705705
.request('/posts')
706706
.then(function() {
@@ -722,7 +722,7 @@ describe('Unit | Mixin | ajax request', function() {
722722
];
723723
this.server.get('/posts', () => response);
724724

725-
const service = new AjaxRequest();
725+
const service = AjaxRequest.create();
726726
return service
727727
.request('/posts')
728728
.then(function() {
@@ -737,7 +737,7 @@ describe('Unit | Mixin | ajax request', function() {
737737
});
738738

739739
it('it throws an error when the user tries to use `.get` to make a request', function() {
740-
const service = new AjaxRequest();
740+
const service = AjaxRequest.create();
741741
service.set('someProperty', 'foo');
742742

743743
expect(service.get('someProperty')).to.equal('foo');
@@ -944,14 +944,14 @@ describe('Unit | Mixin | ajax request', function() {
944944
});
945945

946946
it('correctly handles a host provided on the request options', function() {
947-
const req = new AjaxRequest();
947+
const req = AjaxRequest.create();
948948
expect(req._buildURL('/baz', { host: 'http://foo.com' })).to.equal(
949949
'http://foo.com/baz'
950950
);
951951
});
952952

953953
it('correctly handles no namespace or host', function() {
954-
const req = new AjaxRequest();
954+
const req = AjaxRequest.create();
955955
expect(req._buildURL('/baz')).to.equal('/baz');
956956
expect(req._buildURL('baz')).to.equal('baz');
957957
});
@@ -1039,7 +1039,7 @@ describe('Unit | Mixin | ajax request', function() {
10391039
});
10401040

10411041
it("it doesn't reassign payloads which evaluate falsey", function() {
1042-
const service = new AjaxRequest();
1042+
const service = AjaxRequest.create();
10431043

10441044
const payloadWithFalseyString = service.handleResponse(200, {}, '');
10451045
expect(payloadWithFalseyString).to.be.empty;
@@ -1063,7 +1063,7 @@ describe('Unit | Mixin | ajax request', function() {
10631063
return [200, {}, `${req.queryParams.callback}({ "foo": "bar" })`];
10641064
});
10651065

1066-
const ajax = new AjaxRequest();
1066+
const ajax = AjaxRequest.create();
10671067
return ajax
10681068
.request('/jsonp', {
10691069
dataType: 'jsonp'
@@ -1077,7 +1077,7 @@ describe('Unit | Mixin | ajax request', function() {
10771077
describe('error handlers', function() {
10781078
it('handles a TimeoutError correctly', function() {
10791079
this.server.get('/posts', jsonFactory(200), 2);
1080-
const service = new AjaxRequest();
1080+
const service = AjaxRequest.create();
10811081
return service
10821082
.request('/posts', { timeout: 1 })
10831083
.then(function() {
@@ -1098,7 +1098,7 @@ describe('Unit | Mixin | ajax request', function() {
10981098
errors: [{ id: 1, message: 'error description' }]
10991099
})
11001100
);
1101-
const service = new AjaxRequest();
1101+
const service = AjaxRequest.create();
11021102
return service
11031103
.request('/posts')
11041104
.then(function() {
@@ -1143,7 +1143,7 @@ describe('Unit | Mixin | ajax request', function() {
11431143
});
11441144

11451145
it('can wait on an AJAX GET request', function() {
1146-
const service = new AjaxRequest();
1146+
const service = AjaxRequest.create();
11471147
service.request('/test');
11481148

11491149
return wait().then(() => {
@@ -1152,7 +1152,7 @@ describe('Unit | Mixin | ajax request', function() {
11521152
});
11531153

11541154
it('can wait on an AJAX POST request', function() {
1155-
const service = new AjaxRequest();
1155+
const service = AjaxRequest.create();
11561156
service.post('/test');
11571157

11581158
return wait().then(() => {
@@ -1167,7 +1167,7 @@ describe('Unit | Mixin | ajax request', function() {
11671167
return [200, {}, `${req.queryParams.callback}({ "foo": "bar" })`];
11681168
});
11691169

1170-
const ajax = new AjaxRequest();
1170+
const ajax = AjaxRequest.create();
11711171
ajax
11721172
.request('/jsonp', { dataType: 'jsonp' })
11731173
.then(val => (response = val));
@@ -1183,7 +1183,7 @@ describe('Unit | Mixin | ajax request', function() {
11831183
});
11841184

11851185
it('attaches the XHR for the request to the promise object', function() {
1186-
const ajax = new AjaxRequest();
1186+
const ajax = AjaxRequest.create();
11871187
const promise = ajax.request('/foo');
11881188

11891189
expect(promise.xhr).to.be.ok;
@@ -1192,7 +1192,7 @@ describe('Unit | Mixin | ajax request', function() {
11921192
// Note: the `.catch` handler _must_ be set up before the request is aborted
11931193
// Without that, the rejection will be treated as un-handled
11941194
it('can be used to abort the request', function() {
1195-
const ajax = new AjaxRequest();
1195+
const ajax = AjaxRequest.create();
11961196
const promise = ajax
11971197
.request('/foo')
11981198
.then(() => {
@@ -1210,28 +1210,28 @@ describe('Unit | Mixin | ajax request', function() {
12101210

12111211
describe('passing the XHR to child promises', function() {
12121212
it('keeps the XHR property through child promises (then)', function() {
1213-
const ajax = new AjaxRequest();
1213+
const ajax = AjaxRequest.create();
12141214
const promise = ajax.request('/foo').then(response => response);
12151215

12161216
expect(promise.xhr).to.be.ok;
12171217
});
12181218

12191219
it('keeps the XHR property through child promises (catch)', function() {
1220-
const ajax = new AjaxRequest();
1220+
const ajax = AjaxRequest.create();
12211221
const promise = ajax.request('/foo').catch(response => response);
12221222

12231223
expect(promise.xhr).to.be.ok;
12241224
});
12251225

12261226
it('keeps the XHR property through child promises (finally)', function() {
1227-
const ajax = new AjaxRequest();
1227+
const ajax = AjaxRequest.create();
12281228
const promise = ajax.request('/foo').finally(response => response);
12291229

12301230
expect(promise.xhr).to.be.ok;
12311231
});
12321232

12331233
it('keeps the XHR property through child promises (multiple)', function() {
1234-
const ajax = new AjaxRequest();
1234+
const ajax = AjaxRequest.create();
12351235
const promise = ajax
12361236
.request('/foo')
12371237
.then(response => response)

tests/unit/mixins/legacy/normalize-error-response-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, it } from 'mocha';
44
import LegacyNormalizeErrorResponseMixin from 'ember-ajax/mixins/legacy/normalize-error-response';
55

66
const AjaxRequest = EmberObject.extend(LegacyNormalizeErrorResponseMixin);
7-
const service = new AjaxRequest();
7+
const service = AjaxRequest.create();
88

99
describe('Unit | Mixin | legacy/normalize error response', function() {
1010
it('handles JSON:API formatted error objects', function() {

tests/unit/typescript-usage-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ describe('TypeScript Usage', function() {
2828
});
2929

3030
it('works without the generic defined', async function() {
31-
const ajax = new AjaxRequest();
31+
const ajax = AjaxRequest.create();
3232
const response = await ajax.request('/users/1');
3333

3434
expect(response).to.deep.equal({ name: 'Alex' });
3535
});
3636

3737
it('can provide a generic type to resolve to', async function() {
38-
const ajax = new AjaxRequest();
38+
const ajax = AjaxRequest.create();
3939
const response = await ajax.request<User>('/users/1');
4040

4141
expect(response).to.deep.equal({ name: 'Alex' });

0 commit comments

Comments
 (0)