From 631883226e938f04b1087d88957e84604bbd9109 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 4 May 2017 09:28:47 -0400 Subject: [PATCH 1/2] [BUGFIX beta] Ensure Engines can boot without error. The argument passed into `instance-initializers` is _either_ an `Ember.ApplicationInstance` instance _or_ a `Ember.EngineInstance` instance. The `.application` property is only present on `Ember.ApplicationInstance`'s. This change adds some inline comments around the various conditionals and swaps the logic to use `instance.base` when present and avoid erroring if neither `.base` or `.application` is present. --- .../initialize-store-service.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addon/instance-initializers/initialize-store-service.js b/addon/instance-initializers/initialize-store-service.js index a3199a68d85..4e319ba76b5 100644 --- a/addon/instance-initializers/initialize-store-service.js +++ b/addon/instance-initializers/initialize-store-service.js @@ -5,15 +5,20 @@ import { deprecate } from '@ember/debug'; store. @method initializeStoreService - @param {Ember.ApplicationInstance} applicationOrRegistry + @param {Ember.ApplicationInstance | Ember.EngineInstance} instance */ -export default function initializeStoreService(application) { - const container = application.lookup ? application : application.container; +export default function initializeStoreService(instance) { + // instance.lookup supports Ember 2.1 and higher + // instance.container supports Ember 1.11 - 2.0 + const container = instance.lookup ? instance : instance.container; // Eagerly generate the store so defaultStore is populated. container.lookup('service:store'); - deprecateOldEmberDataInitializers(application.application.constructor.initializers); + // In Ember 2.4+ instance.base is the `Ember.Application` or `Ember.Engine` instance + // In Ember 1.11 - 2.3 we fallback to `instance.application` + let base = instance.base || instance.application; + deprecateOldEmberDataInitializers(base.constructor.initializers); } const DEPRECATED_INITIALIZER_NAMES = ['data-adapter', 'injectStore', 'transforms', 'store']; From e8c265a024d0ac54847a4f410311082ba8c972bd Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 4 May 2017 10:05:43 -0400 Subject: [PATCH 2/2] Ensure initializer deprecation related code is stripped in production builds. --- .../initialize-store-service.js | 75 ++++++++++--------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/addon/instance-initializers/initialize-store-service.js b/addon/instance-initializers/initialize-store-service.js index 4e319ba76b5..8c03288b54e 100644 --- a/addon/instance-initializers/initialize-store-service.js +++ b/addon/instance-initializers/initialize-store-service.js @@ -1,4 +1,7 @@ import { deprecate } from '@ember/debug'; +import { DEBUG } from '@glimmer/env'; + +let deprecateOldEmberDataInitializers; /* Configures a registry for use with an Ember-Data @@ -15,45 +18,49 @@ export default function initializeStoreService(instance) { // Eagerly generate the store so defaultStore is populated. container.lookup('service:store'); - // In Ember 2.4+ instance.base is the `Ember.Application` or `Ember.Engine` instance - // In Ember 1.11 - 2.3 we fallback to `instance.application` - let base = instance.base || instance.application; - deprecateOldEmberDataInitializers(base.constructor.initializers); + if (DEBUG) { + // In Ember 2.4+ instance.base is the `Ember.Application` or `Ember.Engine` instance + // In Ember 1.11 - 2.3 we fallback to `instance.application` + let base = instance.base || instance.application; + deprecateOldEmberDataInitializers(base.constructor.initializers); + } } -const DEPRECATED_INITIALIZER_NAMES = ['data-adapter', 'injectStore', 'transforms', 'store']; +if (DEBUG) { + const DEPRECATED_INITIALIZER_NAMES = ['data-adapter', 'injectStore', 'transforms', 'store']; -function matchesDeprecatedInititalizer(name) { - return DEPRECATED_INITIALIZER_NAMES.indexOf(name) !== -1; -} + let matchesDeprecatedInititalizer = function matchesDeprecatedInititalizer(name) { + return DEPRECATED_INITIALIZER_NAMES.indexOf(name) !== -1; + }; -function deprecateOldEmberDataInitializers(initializers) { - // collect all of the initializers - let keys = Object.keys(initializers); + let warnForDeprecatedInitializers = function warnForDeprecatedInitializers(initializer) { + let deprecatedBeforeInitializer = matchesDeprecatedInititalizer(initializer.before); + let deprecatedAfterInitializer = matchesDeprecatedInititalizer(initializer.after); + let deprecatedProp = deprecatedBeforeInitializer ? 'before' : 'after'; - for (let i = 0; i < keys.length; i++) { - let name = keys[i]; + deprecate( + `The initializer \`${initializer[deprecatedProp]}\` has been deprecated. Please update your \`${initializer.name}\` initializer to use use \`${deprecatedProp}: \'ember-data\'\` instead.`, + !(deprecatedBeforeInitializer || deprecatedAfterInitializer), + { + id: 'ds.deprecated-initializers', + until: '3.0.0' + }); + }; - // filter out all of the Ember Data initializer. We have some - // deprecated initializers that depend on other deprecated - // initializers which may trigger the deprecation warning - // unintentionally. - if (!matchesDeprecatedInititalizer(name)) { - warnForDeprecatedInitializers(initializers[name]); - } - } -} + deprecateOldEmberDataInitializers = function deprecateOldEmberDataInitializers(initializers) { + // collect all of the initializers + let keys = Object.keys(initializers); -function warnForDeprecatedInitializers(initializer) { - let deprecatedBeforeInitializer = matchesDeprecatedInititalizer(initializer.before); - let deprecatedAfterInitializer = matchesDeprecatedInititalizer(initializer.after); - let deprecatedProp = deprecatedBeforeInitializer ? 'before' : 'after'; - - deprecate( - `The initializer \`${initializer[deprecatedProp]}\` has been deprecated. Please update your \`${initializer.name}\` initializer to use use \`${deprecatedProp}: \'ember-data\'\` instead.`, - !(deprecatedBeforeInitializer || deprecatedAfterInitializer), - { - id: 'ds.deprecated-initializers', - until: '3.0.0' - }) + for (let i = 0; i < keys.length; i++) { + let name = keys[i]; + + // filter out all of the Ember Data initializer. We have some + // deprecated initializers that depend on other deprecated + // initializers which may trigger the deprecation warning + // unintentionally. + if (!matchesDeprecatedInititalizer(name)) { + warnForDeprecatedInitializers(initializers[name]); + } + } + }; }