From b80c40e7fb76ec03ea822c57ef2f3f6733046fad Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Tue, 16 Jun 2020 11:55:24 -0500 Subject: [PATCH 01/10] najax deprecation when ember-fetch is also installed --- packages/adapter/addon/rest.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/adapter/addon/rest.js b/packages/adapter/addon/rest.js index d61f7a67137..a76868d9e40 100644 --- a/packages/adapter/addon/rest.js +++ b/packages/adapter/addon/rest.js @@ -5,12 +5,14 @@ */ import { getOwner } from '@ember/application'; +import { deprecate } from '@ember/application/deprecations'; import { warn } from '@ember/debug'; import { computed, get } from '@ember/object'; import { assign } from '@ember/polyfills'; import { run } from '@ember/runloop'; import { DEBUG } from '@glimmer/env'; +import { has } from 'require'; import { Promise } from 'rsvp'; import Adapter, { BuildURLMixin } from '@ember-data/adapter'; @@ -991,7 +993,6 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { */ ajax(url, type, options) { let adapter = this; - let useFetch = get(this, 'useFetch'); let requestData = { url: url, @@ -999,7 +1000,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { }; let hash = adapter.ajaxOptions(url, type, options); - if (useFetch) { + if (this.useFetch) { let _response; return this._fetchRequest(hash) .then(response => { @@ -1067,9 +1068,19 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { }, _ajax(options) { - if (get(this, 'useFetch')) { + if (this.useFetch) { this._fetchRequest(options); } else if (get(this, 'fastboot.isFastBoot')) { + if (has('fetch')) { + deprecate( + 'You have ember-fetch and jquery installed. To use ember-fetch, set `useFetch: true` in your adapter. In 4.0, ember-data will fallback to ember-fetch instead of najax when both of these are installed.', + false, + { + id: 'ember-data:najax-fallback', + until: '4.0', + } + ); + } this._najaxRequest(options); } else { this._ajaxRequest(options); @@ -1103,7 +1114,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { let contentType = options.contentType || this._defaultContentType; - if (get(this, 'useFetch')) { + if (this.useFetch) { if (options.data && options.type !== 'GET') { if (!options.headers['Content-Type'] && !options.headers['content-type']) { options.headers['content-type'] = contentType; From 1fdffcf9400d78fcf70b888779d1a454e9e440ec Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Wed, 17 Jun 2020 21:31:05 -0500 Subject: [PATCH 02/10] strip najax with deprecation util --- packages/adapter/addon/rest.js | 69 +++++++++++-------- .../addon/current-deprecations.ts | 1 + .../private-build-infra/addon/deprecations.ts | 1 + 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/packages/adapter/addon/rest.js b/packages/adapter/addon/rest.js index a76868d9e40..35df72fc204 100644 --- a/packages/adapter/addon/rest.js +++ b/packages/adapter/addon/rest.js @@ -26,6 +26,7 @@ import AdapterError, { TimeoutError, UnauthorizedError, } from '@ember-data/adapter/error'; +import { DEPRECATE_NAJAX } from '@ember-data/private-build-infra/deprecations'; import { determineBodyPromise, fetch, parseResponseHeaders, serializeIntoHash, serializeQueryParams } from './-private'; @@ -311,18 +312,26 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { }, }), - useFetch: computed(function() { - let ENV = getOwner(this).resolveRegistration('config:environment'); - // TODO: https://github.com/emberjs/data/issues/6093 - let jQueryIntegrationDisabled = ENV && ENV.EmberENV && ENV.EmberENV._JQUERY_INTEGRATION === false; - - if (jQueryIntegrationDisabled) { - return true; - } else if (hasNajax || hasJQuery) { - return false; - } else { - return true; - } + useFetch: computed({ + get() { + if (this._useFetch) { + return this._useFetch; + } + let ENV = getOwner(this).resolveRegistration('config:environment'); + // TODO: https://github.com/emberjs/data/issues/6093 + let jQueryIntegrationDisabled = ENV && ENV.EmberENV && ENV.EmberENV._JQUERY_INTEGRATION === false; + + if (jQueryIntegrationDisabled) { + return true; + } else if (hasNajax || hasJQuery) { + return false; + } else { + return true; + } + }, + set(key, value) { + return (this._useFetch = value); + }, }), /** @@ -1040,21 +1049,6 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { jQuery.ajax(options); }, - /** - @method _najaxRequest - @private - @param {Object} options jQuery ajax options to be used for the najax request - */ - _najaxRequest(options) { - if (hasNajax) { - najax(options); - } else { - throw new Error( - 'najax does not seem to be defined in your app. Did you override it via `addOrOverrideSandboxGlobals` in the fastboot server?' - ); - } - }, - _fetchRequest(options) { let fetchFunction = fetch(); @@ -1070,7 +1064,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { _ajax(options) { if (this.useFetch) { this._fetchRequest(options); - } else if (get(this, 'fastboot.isFastBoot')) { + } else if (get(this, 'fastboot.isFastBoot') && DEPRECATE_NAJAX) { if (has('fetch')) { deprecate( 'You have ember-fetch and jquery installed. To use ember-fetch, set `useFetch: true` in your adapter. In 4.0, ember-data will fallback to ember-fetch instead of najax when both of these are installed.', @@ -1425,4 +1419,23 @@ function ajaxOptions(options, adapter) { return options; } +if (DEPRECATE_NAJAX) { + RESTAdapter.reopen({ + /** + @method _najaxRequest + @private + @param {Object} options jQuery ajax options to be used for the najax request + */ + _najaxRequest(options) { + if (hasNajax) { + najax(options); + } else { + throw new Error( + 'najax does not seem to be defined in your app. Did you override it via `addOrOverrideSandboxGlobals` in the fastboot server?' + ); + } + }, + }); +} + export default RESTAdapter; diff --git a/packages/private-build-infra/addon/current-deprecations.ts b/packages/private-build-infra/addon/current-deprecations.ts index 0b17935d5d4..1605194f112 100644 --- a/packages/private-build-infra/addon/current-deprecations.ts +++ b/packages/private-build-infra/addon/current-deprecations.ts @@ -51,4 +51,5 @@ export default { DEPRECATE_SERIALIZER_QUERY_RECORD_ARRAY_RESPONSE: '3.4', DEPRECATE_BELONGS_TO_REFERENCE_PUSH: '3.16', DEPRECATE_REFERENCE_INTERNAL_MODEL: '3.19', + DEPRECATE_NAJAX: '4.0', }; diff --git a/packages/private-build-infra/addon/deprecations.ts b/packages/private-build-infra/addon/deprecations.ts index 2863e340de6..08a1b28f998 100644 --- a/packages/private-build-infra/addon/deprecations.ts +++ b/packages/private-build-infra/addon/deprecations.ts @@ -24,3 +24,4 @@ export const DEPRECATE_MISMATCHED_INVERSE_RELATIONSHIP_DATA = deprecationState( ); export const DEPRECATE_BELONGS_TO_REFERENCE_PUSH = deprecationState('DEPRECATE_BELONGS_TO_REFERENCE_PUSH'); export const DEPRECATE_REFERENCE_INTERNAL_MODEL = deprecationState('DEPRECATE_REFERENCE_INTERNAL_MODEL'); +export const DEPRECATE_NAJAX = deprecationState('DEPRECATE_NAJAX'); From d34d7c18578cf8cedd02a299d3884ab30c98ec7e Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Thu, 18 Jun 2020 16:15:32 -0500 Subject: [PATCH 03/10] address some comments --- packages/adapter/addon/rest.js | 8 ++++---- .../private-build-infra/addon/current-deprecations.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/adapter/addon/rest.js b/packages/adapter/addon/rest.js index 35df72fc204..a0c50826d64 100644 --- a/packages/adapter/addon/rest.js +++ b/packages/adapter/addon/rest.js @@ -293,7 +293,7 @@ const hasNajax = typeof najax !== 'undefined'; @extends Adapter @uses BuildURLMixin */ -const RESTAdapter = Adapter.extend(BuildURLMixin, { +let RESTAdapter = Adapter.extend(BuildURLMixin, { defaultSerializer: '-rest', _defaultContentType: 'application/json; charset=utf-8', @@ -314,7 +314,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { useFetch: computed({ get() { - if (this._useFetch) { + if (this._useFetch !== undefined) { return this._useFetch; } let ENV = getOwner(this).resolveRegistration('config:environment'); @@ -1064,7 +1064,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { _ajax(options) { if (this.useFetch) { this._fetchRequest(options); - } else if (get(this, 'fastboot.isFastBoot') && DEPRECATE_NAJAX) { + } else if (DEPRECATE_NAJAX && get(this, 'fastboot.isFastBoot')) { if (has('fetch')) { deprecate( 'You have ember-fetch and jquery installed. To use ember-fetch, set `useFetch: true` in your adapter. In 4.0, ember-data will fallback to ember-fetch instead of najax when both of these are installed.', @@ -1420,7 +1420,7 @@ function ajaxOptions(options, adapter) { } if (DEPRECATE_NAJAX) { - RESTAdapter.reopen({ + RESTAdapter = RESTAdapter.extend({ /** @method _najaxRequest @private diff --git a/packages/private-build-infra/addon/current-deprecations.ts b/packages/private-build-infra/addon/current-deprecations.ts index 1605194f112..096ad6b54fe 100644 --- a/packages/private-build-infra/addon/current-deprecations.ts +++ b/packages/private-build-infra/addon/current-deprecations.ts @@ -1,7 +1,7 @@ /** * ## Deprecations * - * EmberData allows users to remove code that exists to support deprecated + * EmberData allows users to opt-in and remove code that exists to support deprecated * behaviors. * * If your app has resolved all deprecations present in a given version, @@ -51,5 +51,5 @@ export default { DEPRECATE_SERIALIZER_QUERY_RECORD_ARRAY_RESPONSE: '3.4', DEPRECATE_BELONGS_TO_REFERENCE_PUSH: '3.16', DEPRECATE_REFERENCE_INTERNAL_MODEL: '3.19', - DEPRECATE_NAJAX: '4.0', + DEPRECATE_NAJAX: '3.21', }; From 3aa605798afbddfd2127463096c76ce54441e027 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Thu, 18 Jun 2020 17:06:27 -0500 Subject: [PATCH 04/10] set _useFetch in getter --- packages/adapter/addon/rest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/adapter/addon/rest.js b/packages/adapter/addon/rest.js index a0c50826d64..3c12738efbb 100644 --- a/packages/adapter/addon/rest.js +++ b/packages/adapter/addon/rest.js @@ -302,7 +302,7 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { // Avoid computed property override deprecation in fastboot as suggested by: // https://deprecations.emberjs.com/v3.x/#toc_computed-property-override get() { - if (this._fastboot) { + if (this._fastboot !== undefined) { return this._fastboot; } return (this._fastboot = getOwner(this).lookup('service:fastboot')); @@ -326,7 +326,7 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { } else if (hasNajax || hasJQuery) { return false; } else { - return true; + return (this._useFetch = true); } }, set(key, value) { From 984a577bc400528a0c96c1dc9562e130493437e2 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Wed, 24 Jun 2020 15:18:28 -0500 Subject: [PATCH 05/10] address feedback with feature flag and comments --- packages/adapter/addon/rest.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/adapter/addon/rest.js b/packages/adapter/addon/rest.js index 3c12738efbb..3d374a3cf0e 100644 --- a/packages/adapter/addon/rest.js +++ b/packages/adapter/addon/rest.js @@ -31,7 +31,6 @@ import { DEPRECATE_NAJAX } from '@ember-data/private-build-infra/deprecations'; import { determineBodyPromise, fetch, parseResponseHeaders, serializeIntoHash, serializeQueryParams } from './-private'; const hasJQuery = typeof jQuery !== 'undefined'; -const hasNajax = typeof najax !== 'undefined'; /** The REST adapter allows your store to communicate with an HTTP server by @@ -302,7 +301,7 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { // Avoid computed property override deprecation in fastboot as suggested by: // https://deprecations.emberjs.com/v3.x/#toc_computed-property-override get() { - if (this._fastboot !== undefined) { + if (this._fastboot) { return this._fastboot; } return (this._fastboot = getOwner(this).lookup('service:fastboot')); @@ -323,7 +322,9 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { if (jQueryIntegrationDisabled) { return true; - } else if (hasNajax || hasJQuery) { + } else if (DEPRECATE_NAJAX && typeof najax !== 'undefined') { + return false; + } else if (hasJQuery) { return false; } else { return (this._useFetch = true); @@ -1067,7 +1068,16 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { } else if (DEPRECATE_NAJAX && get(this, 'fastboot.isFastBoot')) { if (has('fetch')) { deprecate( - 'You have ember-fetch and jquery installed. To use ember-fetch, set `useFetch: true` in your adapter. In 4.0, ember-data will fallback to ember-fetch instead of najax when both of these are installed.', + 'You have ember-fetch and jquery installed. To use ember-fetch, set `useFetch: true` in your adapter. In 4.0, ember-data will fallback to ember-fetch instead of najax when both ember-fetch and jquery are installed in FastBoot.', + false, + { + id: 'ember-data:najax-fallback', + until: '4.0', + } + ); + } else { + deprecate( + 'In 4.0, ember-data will default to ember-fetch instead of najax in FastBoot. It is recommended that you install ember-fetch or similar as a fetch polyfill in FastBoot.', false, { id: 'ember-data:najax-fallback', @@ -1427,7 +1437,7 @@ if (DEPRECATE_NAJAX) { @param {Object} options jQuery ajax options to be used for the najax request */ _najaxRequest(options) { - if (hasNajax) { + if (typeof najax !== 'undefined') { najax(options); } else { throw new Error( From 3555dec227f47ed14c6c570763253322953150ac Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 28 Jun 2020 21:38:28 -0500 Subject: [PATCH 06/10] cache off of value in all return branches --- packages/adapter/addon/rest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/adapter/addon/rest.js b/packages/adapter/addon/rest.js index 3d374a3cf0e..2543f24f063 100644 --- a/packages/adapter/addon/rest.js +++ b/packages/adapter/addon/rest.js @@ -321,11 +321,11 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { let jQueryIntegrationDisabled = ENV && ENV.EmberENV && ENV.EmberENV._JQUERY_INTEGRATION === false; if (jQueryIntegrationDisabled) { - return true; + return (this._useFetch = true); } else if (DEPRECATE_NAJAX && typeof najax !== 'undefined') { - return false; + return (this._useFetch = false); } else if (hasJQuery) { - return false; + return (this._useFetch = false); } else { return (this._useFetch = true); } From 61d9abe7b5da3631f6eb628e7907e6dab329fe61 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Thu, 27 Aug 2020 15:09:12 -0700 Subject: [PATCH 07/10] move to useFetech --- packages/adapter/addon/rest.js | 41 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/adapter/addon/rest.js b/packages/adapter/addon/rest.js index 2543f24f063..045b0b4da80 100644 --- a/packages/adapter/addon/rest.js +++ b/packages/adapter/addon/rest.js @@ -5,8 +5,7 @@ */ import { getOwner } from '@ember/application'; -import { deprecate } from '@ember/application/deprecations'; -import { warn } from '@ember/debug'; +import { deprecate, warn } from '@ember/debug'; import { computed, get } from '@ember/object'; import { assign } from '@ember/polyfills'; import { run } from '@ember/runloop'; @@ -323,6 +322,25 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { if (jQueryIntegrationDisabled) { return (this._useFetch = true); } else if (DEPRECATE_NAJAX && typeof najax !== 'undefined') { + if (has('fetch')) { + deprecate( + 'You have ember-fetch and jquery installed. To use ember-fetch, set `useFetch: true` in your adapter. In 4.0, ember-data will fallback to ember-fetch instead of najax when both ember-fetch and jquery are installed in FastBoot.', + false, + { + id: 'ember-data:najax-fallback', + until: '4.0', + } + ); + } else { + deprecate( + 'In 4.0, ember-data will default to ember-fetch instead of najax in FastBoot. It is recommended that you install ember-fetch or similar as a fetch polyfill in FastBoot.', + false, + { + id: 'ember-data:najax-fallback', + until: '4.0', + } + ); + } return (this._useFetch = false); } else if (hasJQuery) { return (this._useFetch = false); @@ -1066,25 +1084,6 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { if (this.useFetch) { this._fetchRequest(options); } else if (DEPRECATE_NAJAX && get(this, 'fastboot.isFastBoot')) { - if (has('fetch')) { - deprecate( - 'You have ember-fetch and jquery installed. To use ember-fetch, set `useFetch: true` in your adapter. In 4.0, ember-data will fallback to ember-fetch instead of najax when both ember-fetch and jquery are installed in FastBoot.', - false, - { - id: 'ember-data:najax-fallback', - until: '4.0', - } - ); - } else { - deprecate( - 'In 4.0, ember-data will default to ember-fetch instead of najax in FastBoot. It is recommended that you install ember-fetch or similar as a fetch polyfill in FastBoot.', - false, - { - id: 'ember-data:najax-fallback', - until: '4.0', - } - ); - } this._najaxRequest(options); } else { this._ajaxRequest(options); From 117122a5f45a21ffcac011608c3d6272ac32ab64 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Thu, 27 Aug 2020 15:09:23 -0700 Subject: [PATCH 08/10] Change to 3.22 for deprecation starting --- packages/private-build-infra/addon/current-deprecations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/private-build-infra/addon/current-deprecations.ts b/packages/private-build-infra/addon/current-deprecations.ts index 096ad6b54fe..e81cdb11e5a 100644 --- a/packages/private-build-infra/addon/current-deprecations.ts +++ b/packages/private-build-infra/addon/current-deprecations.ts @@ -51,5 +51,5 @@ export default { DEPRECATE_SERIALIZER_QUERY_RECORD_ARRAY_RESPONSE: '3.4', DEPRECATE_BELONGS_TO_REFERENCE_PUSH: '3.16', DEPRECATE_REFERENCE_INTERNAL_MODEL: '3.19', - DEPRECATE_NAJAX: '3.21', + DEPRECATE_NAJAX: '3.22', }; From b8fd8a6ebde09af2ca69010c6914b09c30c7c8ca Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Thu, 27 Aug 2020 15:11:42 -0700 Subject: [PATCH 09/10] improve wording of deprecation a bit --- packages/adapter/addon/rest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/adapter/addon/rest.js b/packages/adapter/addon/rest.js index 045b0b4da80..d57be630126 100644 --- a/packages/adapter/addon/rest.js +++ b/packages/adapter/addon/rest.js @@ -324,7 +324,7 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { } else if (DEPRECATE_NAJAX && typeof najax !== 'undefined') { if (has('fetch')) { deprecate( - 'You have ember-fetch and jquery installed. To use ember-fetch, set `useFetch: true` in your adapter. In 4.0, ember-data will fallback to ember-fetch instead of najax when both ember-fetch and jquery are installed in FastBoot.', + 'You have ember-fetch and jquery installed. To use ember-fetch instead of najax, set `useFetch: true` in your adapter. In 4.0, ember-data will default to ember-fetch instead of najax when both ember-fetch and jquery are installed in FastBoot.', false, { id: 'ember-data:najax-fallback', @@ -333,7 +333,7 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { ); } else { deprecate( - 'In 4.0, ember-data will default to ember-fetch instead of najax in FastBoot. It is recommended that you install ember-fetch or similar as a fetch polyfill in FastBoot.', + 'In 4.0, ember-data will default to ember-fetch instead of najax in FastBoot. It is recommended that you install ember-fetch or similar fetch polyfill in FastBoot.', false, { id: 'ember-data:najax-fallback', From 401a23e6e84624aac586d57c90922e4777ef5e9f Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Thu, 8 Oct 2020 20:52:51 -0700 Subject: [PATCH 10/10] Address comments with DEPRECATE_NAJAX and useFetch defaulting to true otherwise, if the consuming app has compatWith > 3.22, any najax related code will be stripped --- .../node-tests/fixtures/expected.js | 1 + packages/adapter/addon/rest.js | 101 ++++++++++-------- packages/store/addon/-private/index.ts | 1 + 3 files changed, 61 insertions(+), 42 deletions(-) diff --git a/packages/-ember-data/node-tests/fixtures/expected.js b/packages/-ember-data/node-tests/fixtures/expected.js index 7013ab27547..ce83d98a8b0 100644 --- a/packages/-ember-data/node-tests/fixtures/expected.js +++ b/packages/-ember-data/node-tests/fixtures/expected.js @@ -166,6 +166,7 @@ module.exports = { '(public) @ember-data/adapter RESTAdapter#queryRecord', '(public) @ember-data/adapter RESTAdapter#sortQueryParams', '(public) @ember-data/adapter RESTAdapter#updateRecord', + '(public) @ember-data/adapter RESTAdapter#useFetch', '(public) @ember-data/debug InspectorDataAdapter#watchModelTypes', '(public) @ember-data/model @ember-data/model#attr', '(public) @ember-data/model @ember-data/model#belongsTo', diff --git a/packages/adapter/addon/rest.js b/packages/adapter/addon/rest.js index d57be630126..5fa412f0666 100644 --- a/packages/adapter/addon/rest.js +++ b/packages/adapter/addon/rest.js @@ -26,9 +26,11 @@ import AdapterError, { UnauthorizedError, } from '@ember-data/adapter/error'; import { DEPRECATE_NAJAX } from '@ember-data/private-build-infra/deprecations'; +import { addSymbol, symbol } from '@ember-data/store/-private'; import { determineBodyPromise, fetch, parseResponseHeaders, serializeIntoHash, serializeQueryParams } from './-private'; +const UseFetch = symbol('useFetch'); const hasJQuery = typeof jQuery !== 'undefined'; /** @@ -310,48 +312,12 @@ let RESTAdapter = Adapter.extend(BuildURLMixin, { }, }), - useFetch: computed({ - get() { - if (this._useFetch !== undefined) { - return this._useFetch; - } - let ENV = getOwner(this).resolveRegistration('config:environment'); - // TODO: https://github.com/emberjs/data/issues/6093 - let jQueryIntegrationDisabled = ENV && ENV.EmberENV && ENV.EmberENV._JQUERY_INTEGRATION === false; - - if (jQueryIntegrationDisabled) { - return (this._useFetch = true); - } else if (DEPRECATE_NAJAX && typeof najax !== 'undefined') { - if (has('fetch')) { - deprecate( - 'You have ember-fetch and jquery installed. To use ember-fetch instead of najax, set `useFetch: true` in your adapter. In 4.0, ember-data will default to ember-fetch instead of najax when both ember-fetch and jquery are installed in FastBoot.', - false, - { - id: 'ember-data:najax-fallback', - until: '4.0', - } - ); - } else { - deprecate( - 'In 4.0, ember-data will default to ember-fetch instead of najax in FastBoot. It is recommended that you install ember-fetch or similar fetch polyfill in FastBoot.', - false, - { - id: 'ember-data:najax-fallback', - until: '4.0', - } - ); - } - return (this._useFetch = false); - } else if (hasJQuery) { - return (this._useFetch = false); - } else { - return (this._useFetch = true); - } - }, - set(key, value) { - return (this._useFetch = value); - }, - }), + /** + @property useFetch + @type {Boolean} + @public + */ + useFetch: true, /** By default, the RESTAdapter will send the query params sorted alphabetically to the @@ -1444,6 +1410,57 @@ if (DEPRECATE_NAJAX) { ); } }, + + useFetch: computed({ + get() { + if (this[UseFetch]) { + return this[UseFetch]; + } + + let ENV = getOwner(this).resolveRegistration('config:environment'); + // TODO: https://github.com/emberjs/data/issues/6093 + let jQueryIntegrationDisabled = ENV && ENV.EmberENV && ENV.EmberENV._JQUERY_INTEGRATION === false; + + let shouldUseFetch; + if (jQueryIntegrationDisabled) { + shouldUseFetch = true; + } else if (typeof najax !== 'undefined') { + if (has('fetch')) { + deprecate( + 'You have ember-fetch and jquery installed. To use ember-fetch instead of najax, set `useFetch = true` in your adapter. In 4.0, ember-data will default to ember-fetch instead of najax when both ember-fetch and jquery are installed in FastBoot.', + false, + { + id: 'ember-data:najax-fallback', + until: '4.0', + } + ); + } else { + deprecate( + 'In 4.0, ember-data will default to ember-fetch instead of najax in FastBoot. It is recommended that you install ember-fetch or similar fetch polyfill in FastBoot and set `useFetch = true` in your adapter.', + false, + { + id: 'ember-data:najax-fallback', + until: '4.0', + } + ); + } + + shouldUseFetch = false; + } else if (hasJQuery) { + shouldUseFetch = false; + } else { + shouldUseFetch = true; + } + + addSymbol(this, UseFetch, shouldUseFetch); + + return shouldUseFetch; + }, + set(key, value) { + addSymbol(this, UseFetch, value); + return value; + }, + }), }); } diff --git a/packages/store/addon/-private/index.ts b/packages/store/addon/-private/index.ts index 30a992d02eb..59f44ffe4ef 100644 --- a/packages/store/addon/-private/index.ts +++ b/packages/store/addon/-private/index.ts @@ -25,6 +25,7 @@ export { default as RootState } from './system/model/states'; export { default as InternalModel } from './system/model/internal-model'; export { PromiseArray, PromiseObject } from './system/promise-proxies'; +export { addSymbol, symbol } from './utils/symbol'; export { RecordArray, AdapterPopulatedRecordArray } from './system/record-arrays';