forked from emberjs/data
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request emberjs#4969 from rwjblue/fix-engines
[BUGFIX beta] Ensure Engines can boot without error.
- Loading branch information
Showing
1 changed file
with
46 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,66 @@ | ||
import { deprecate } from '@ember/debug'; | ||
import { DEBUG } from '@glimmer/env'; | ||
|
||
let deprecateOldEmberDataInitializers; | ||
|
||
/* | ||
Configures a registry for use with an Ember-Data | ||
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); | ||
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]); | ||
} | ||
} | ||
}; | ||
} |