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

Deprecate unused initializers #4657

Merged
merged 1 commit into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
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
51 changes: 46 additions & 5 deletions addon/-private/instance-initializers/initialize-store-service.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
import { deprecate } from 'ember-data/-private/debug';
/*
Configures a registry for use with an Ember-Data
store.
Configures a registry for use with an Ember-Data
store.

@method initializeStoreService
@param {Ember.ApplicationInstance} applicationOrRegistry
*/
@method initializeStoreService
@param {Ember.ApplicationInstance} applicationOrRegistry
*/
export default function initializeStoreService(application) {
var container = application.lookup ? application : application.container;
// Eagerly generate the store so defaultStore is populated.
container.lookup('service:store');

let initializers = application.application.constructor.initializers;
deprecateOldEmberDataInitializers(initializers)
}



let deprecatedInitializerNames = ['data-adapter', 'injectStore', 'transforms', 'store'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store should not be included in this list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. This code is correct. I got store confused with the ember-data initializer.


function matchesDeprecatedInititalizer(name) {
return deprecatedInitializerNames.indexOf(name) !== -1;
}

function deprecateOldEmberDataInitializers(initializers) {
// collect all of the initializers
let initializersArray = Object.keys(initializers).map(key => initializers[key]);

// 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.
let nonEmberDataInitializers = initializersArray.filter((initializer) => {
return !matchesDeprecatedInititalizer(initializer.name)
})

nonEmberDataInitializers.forEach(warnForDeprecatedInitializers)
}

function warnForDeprecatedInitializers(initializer) {
var deprecatedBeforeInitializer = matchesDeprecatedInititalizer(initializer.before)
var 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'
})
}
31 changes: 19 additions & 12 deletions tests/integration/application-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import testInDebug from 'dummy/tests/helpers/test-in-debug';

import {module, test} from 'qunit';

Expand Down Expand Up @@ -182,47 +183,53 @@ test("ember-data initializer does not register the store service when it was alr

});

test("store initializer is run (DEPRECATED)", function(assert) {
testInDebug("store initializer is run (DEPRECATED)", function(assert) {
var ran = false;
App.initializer({
name: "after-store",
after: 'store',
initialize() { ran = true; }
});

run(function() {
app = App.create();
});
assert.expectDeprecation(function() {
run(function() {
app = App.create();
});
}, /The initializer `store` has been deprecated/)

assert.ok(ran, 'store initializer was found');
});

test("injectStore initializer is run (DEPRECATED)", function(assert) {
testInDebug("injectStore initializer is run (DEPRECATED)", function(assert) {
var ran = false;
App.initializer({
name: "after-store",
after: 'injectStore',
initialize() { ran = true; }
});

run(function() {
app = App.create();
});
assert.expectDeprecation(function() {
run(function() {
app = App.create();
});
}, /The initializer `injectStore` has been deprecated/)

assert.ok(ran, 'injectStore initializer was found');
});

test("transforms initializer is run (DEPRECATED)", function(assert) {
testInDebug("transforms initializer is run (DEPRECATED)", function(assert) {
var ran = false;
App.initializer({
name: "after-store",
after: 'transforms',
initialize() { ran = true; }
});

run(function() {
app = App.create();
});
assert.expectDeprecation(function() {
run(function() {
app = App.create();
});
}, /The initializer `transforms` has been deprecated/)

assert.ok(ran, 'transforms initializer was found');
});