Skip to content

Commit

Permalink
Merge pull request emberjs#4969 from rwjblue/fix-engines
Browse files Browse the repository at this point in the history
[BUGFIX beta] Ensure Engines can boot without error.
  • Loading branch information
bmac authored May 4, 2017
2 parents e6cb564 + e8c265a commit b9f7e01
Showing 1 changed file with 46 additions and 34 deletions.
80 changes: 46 additions & 34 deletions addon/instance-initializers/initialize-store-service.js
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]);
}
}
};
}

0 comments on commit b9f7e01

Please sign in to comment.