diff --git a/addon/-private/instance-initializers/initialize-store-service.js b/addon/-private/instance-initializers/initialize-store-service.js index b2d9fa1ec99..ed4e8b92af4 100644 --- a/addon/-private/instance-initializers/initialize-store-service.js +++ b/addon/-private/instance-initializers/initialize-store-service.js @@ -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']; + +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' + }) } diff --git a/tests/integration/application-test.js b/tests/integration/application-test.js index 519d359c2fa..43316c3bd41 100644 --- a/tests/integration/application-test.js +++ b/tests/integration/application-test.js @@ -1,4 +1,5 @@ import Ember from 'ember'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; import {module, test} from 'qunit'; @@ -182,7 +183,7 @@ 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", @@ -190,14 +191,16 @@ test("store initializer is run (DEPRECATED)", function(assert) { 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", @@ -205,14 +208,16 @@ test("injectStore initializer is run (DEPRECATED)", function(assert) { 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", @@ -220,9 +225,11 @@ test("transforms initializer is run (DEPRECATED)", function(assert) { 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'); });