diff --git a/addon/ajax-request.js b/addon/ajax-request.js index 2478f6ba..5ff21ac6 100644 --- a/addon/ajax-request.js +++ b/addon/ajax-request.js @@ -42,18 +42,14 @@ function isJSONAPIContentType(header) { return header.indexOf(JSONAPIContentType) === 0; } -export default class AjaxRequest { - - constructor() { - this.init(); - } +let pendingRequestCount = 0; +if (testing) { + Test.registerWaiter(function() { + return pendingRequestCount === 0; + }); +} - init() { - this.pendingRequestCount = 0; - if (testing) { - Test.registerWaiter(() => this.pendingRequestCount === 0); - } - } +export default class AjaxRequest { request(url, options) { const hash = this.options(url, options); @@ -90,7 +86,7 @@ export default class AjaxRequest { requestData ); - this.pendingRequestCount--; + pendingRequestCount--; if (isAjaxError(response)) { run.join(null, reject, { payload, textStatus, jqXHR, response }); @@ -118,12 +114,12 @@ export default class AjaxRequest { ); } - this.pendingRequestCount--; + pendingRequestCount--; run.join(null, reject, { payload, textStatus, jqXHR, errorThrown, response }); }; - this.pendingRequestCount++; + pendingRequestCount++; ajax(hash); }, `ember-ajax: ${hash.type} ${hash.url}`); @@ -216,7 +212,6 @@ export default class AjaxRequest { options.url = this._buildURL(url, options); options.type = options.type || 'GET'; options.dataType = options.dataType || 'json'; - options.context = this; if (this._shouldSendHeaders(options)) { options.headers = this._getFullHeadersHash(options.headers); diff --git a/tests/unit/ajax-request-test.js b/tests/unit/ajax-request-test.js index f5b42f7d..419ef5a9 100644 --- a/tests/unit/ajax-request-test.js +++ b/tests/unit/ajax-request-test.js @@ -168,7 +168,6 @@ test('options() sets raw data', function(assert) { const ajaxOptions = service.options(url, { type, data: { key: 'value' } }); assert.deepEqual(ajaxOptions, { - context: service, data: { key: 'value' }, @@ -195,7 +194,6 @@ test('options() sets options correctly', function(assert) { assert.deepEqual(ajaxOptions, { contentType: 'application/json; charset=utf-8', - context: service, data: '{"key":"value"}', dataType: 'json', headers: {}, @@ -211,7 +209,6 @@ test('options() empty data', function(assert) { const ajaxOptions = service.options(url, { type }); assert.deepEqual(ajaxOptions, { - context: service, dataType: 'json', headers: {}, type: 'POST',