Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Ensure Engines can boot without error. #4969

Merged
merged 2 commits into from
May 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]);
}
}
};
}