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

Remove deprecated code from the Ember Data initializer #3489

Merged
merged 1 commit into from
Jul 6, 2015
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
20 changes: 6 additions & 14 deletions packages/ember-data/lib/ember-initializer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initializeInjects } from 'ember-data/setup-container';
import setupContainer from 'ember-data/setup-container';
import initializeStoreService from 'ember-data/instance-initializers/initialize-store-service';


Expand Down Expand Up @@ -44,21 +44,13 @@ Ember.onLoad('Ember.Application', function(Application) {

Application.initializer({
name: "ember-data",
initialize: initializeInjects
initialize: setupContainer
});

if (Application.instanceInitializer) {
Application.instanceInitializer({
name: "ember-data",
initialize: initializeStoreService
});
} else {
Application.initializer({
name: "ember-data-store-service",
after: "ember-data",
initialize: initializeStoreService
});
}
Application.instanceInitializer({
name: "ember-data",
initialize: initializeStoreService
});

// Deprecated initializers to satisfy old code that depended on them
Application.initializer({
Expand Down
40 changes: 2 additions & 38 deletions packages/ember-data/lib/initializers/store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Store from "ember-data/system/store";
import { JSONAPISerializer, JSONSerializer, RESTSerializer } from "ember-data/serializers";
import { JSONAPIAdapter, RESTAdapter } from "ember-data/adapters";
import ContainerProxy from "ember-data/system/container-proxy";

/**
Configures a registry for use with an Ember-Data
Expand All @@ -12,21 +11,9 @@ import ContainerProxy from "ember-data/system/container-proxy";
@param {Object} [application] an application namespace
*/
export default function initializeStore(registry, application) {
Ember.deprecate('Specifying a custom Store for Ember Data on your global namespace as `App.Store` ' +
'has been deprecated. Please use `App.ApplicationStore` instead.', !(application && application.Store));

registry.optionsForType('serializer', { singleton: false });
registry.optionsForType('adapter', { singleton: false });

// allow older names to be looked up
var proxy = new ContainerProxy(registry);
proxy.registerDeprecations([
{ deprecated: 'serializer:_default', valid: 'serializer:-default' },
{ deprecated: 'serializer:_rest', valid: 'serializer:-rest' },
{ deprecated: 'adapter:_rest', valid: 'adapter:-rest' }
]);

// new go forward paths
registry.register('serializer:-default', JSONSerializer);
registry.register('serializer:-rest', RESTSerializer);
registry.register('adapter:-rest', RESTAdapter);
Expand All @@ -35,30 +22,7 @@ export default function initializeStore(registry, application) {
registry.register('serializer:-json-api', JSONAPISerializer);


var store;
if (registry.has('store:main')) {
Ember.deprecate('Registering a custom store as `store:main` or defining a store in app/store.js has been deprecated. Please move you store to `service:store` or define your custom store in `app/services/store.js`');
store = registry.lookup('store:main');
} else {
var storeMainProxy = new ContainerProxy(registry);
storeMainProxy.registerDeprecations([
{ deprecated: 'store:main', valid: 'service:store' }
]);
}

if (registry.has('store:application')) {
Ember.deprecate('Registering a custom store as `store:application` or defining a store in app/stores/application.js has been deprecated. Please move you store to `service:store` or define your custom store in `app/services/store.js`');
store = registry.lookup('store:application');
} else {
var storeApplicationProxy = new ContainerProxy(registry);
storeApplicationProxy.registerDeprecations([
{ deprecated: 'store:application', valid: 'service:store' }
]);
}

if (store) {
registry.register('service:store', store, { instantiate: false });
} else if (!registry.has('service:store')) {
registry.register('service:store', application && application.Store || Store);
if (!registry.has('service:store')) {
registry.register('service:store', Store);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,8 @@
@method initializeStore
@param {Ember.ApplicationInstance} applicationOrRegistry
*/
export default function initializeStoreService(applicationOrRegistry) {
var registry, container;
if (applicationOrRegistry.registry && applicationOrRegistry.container) {
// initializeStoreService was registered with an
// instanceInitializer. The first argument is the application
// instance.
registry = applicationOrRegistry.registry;
container = applicationOrRegistry.container;
} else {
// initializeStoreService was called by an initializer instead of
// an instanceInitializer. The first argument is a registy. This
// case allows ED to support Ember pre 1.12
registry = applicationOrRegistry;
if (registry.container) { // Support Ember 1.10 - 1.11
container = registry.container();
} else { // Support Ember 1.9
container = registry;
}
}

export default function initializeStoreService(application) {
var container = application.container;
// Eagerly generate the store so defaultStore is populated.
container.lookup('service:store');
}
7 changes: 0 additions & 7 deletions packages/ember-data/lib/setup-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ import initializeStore from 'ember-data/initializers/store';
import initializeTransforms from 'ember-data/initializers/transforms';
import initializeStoreInjections from 'ember-data/initializers/store-injections';
import initializeDataAdapter from 'ember-data/initializers/data-adapter';
import initializeStoreService from 'ember-data/instance-initializers/initialize-store-service';

export default function setupContainer(registry, application) {
// application is not a required argument. This ensures
// testing setups can setup a container without booting an
// entire ember application.

initializeInjects(registry, application);
initializeStoreService(registry);
}


export function initializeInjects(registry, application) {
initializeDataAdapter(registry, application);
initializeTransforms(registry, application);
initializeStoreInjections(registry, application);
Expand Down
25 changes: 0 additions & 25 deletions packages/ember-data/tests/integration/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,6 @@ test("If a store is instantiated, it should be made available to each controller
ok(isCustom, "the custom store was injected");
});

test("registering App.Store is deprecated but functional", function() {
run(app, 'destroy');

expectDeprecation(function() {
run(function() {
app = Application.create({
Store: DS.Store.extend({ isCustomButDeprecated: true }),
FooController: Controller.extend()
});
});
container = app.__container__;
}, 'Specifying a custom Store for Ember Data on your global namespace as `App.Store` ' +
'has been deprecated. Please use `App.ApplicationStore` instead.');

run(function() {
ok(lookup('service:store').get('isCustomButDeprecated'), "the custom store was instantiated");
});

var fooController = lookup('controller:foo');
run(function() {
ok(fooController.get('store.isCustomButDeprecated'), "the custom store was injected");
});
});

test("The JSONAPIAdapter is the default adapter when no custom adapter is provided", function() {
run(function() {
var store = getStore();
Expand All @@ -86,7 +62,6 @@ test("The JSONAPIAdapter is the default adapter when no custom adapter is provid
});
});


module("integration/application - Injecting the Default Store", {
setup: function() {
run(function() {
Expand Down
56 changes: 0 additions & 56 deletions packages/ember-data/tests/integration/setup-container-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,69 +43,13 @@ test("If a store is instantiated, it should be made available to each controller
ok(fooController.get('store') instanceof Store, "the store was injected");
});

test("the deprecated serializer:_default is resolved as serializer:default", function() {
var deprecated;
var valid = container.lookup('serializer:-default');
expectDeprecation(function() {
deprecated = container.lookup('serializer:_default');
});

ok(deprecated.constructor === valid.constructor, "they should resolve to the same thing");
});

test("the deprecated serializer:_rest is resolved as serializer:rest", function() {
var deprecated;
var valid = container.lookup('serializer:-rest');
expectDeprecation(function() {
deprecated = container.lookup('serializer:_rest');
});

ok(deprecated.constructor === valid.constructor, "they should resolve to the same thing");
});

test("the deprecated adapter:_rest is resolved as adapter:rest", function() {
var deprecated;
var valid = container.lookup('adapter:-rest');
expectDeprecation(function() {
deprecated = container.lookup('adapter:_rest');
});

ok(deprecated.constructor === valid.constructor, "they should resolve to the same thing");
});

test("a deprecation is made when looking up adapter:_rest", function() {
expectDeprecation(function() {
container.lookup('serializer:_default');
}, "You tried to look up 'serializer:_default', but this has been deprecated in favor of 'serializer:-default'.");
});

test("serializers are not returned as singletons - each lookup should return a different instance", function() {
var serializer1, serializer2;
serializer1 = container.lookup('serializer:-rest');
serializer2 = container.lookup('serializer:-rest');
notEqual(serializer1, serializer2);
});

test("the deprecated store:main is resolved as service:store", function() {
var deprecated;
var valid = container.lookup('service:store');
expectDeprecation(function() {
deprecated = container.lookup('store:main');
});

ok(deprecated.constructor === valid.constructor, "they should resolve to the same thing");
});

test("the deprecated store:application is resolved as service:store", function() {
var deprecated;
var valid = container.lookup('service:store');
expectDeprecation(function() {
deprecated = container.lookup('store:application');
});

ok(deprecated.constructor === valid.constructor, "they should resolve to the same thing");
});

test("adapters are not returned as singletons - each lookup should return a different instance", function() {
var adapter1, adapter2;
adapter1 = container.lookup('adapter:-rest');
Expand Down