Skip to content

Commit

Permalink
Register service:store in an initializer instead of an instanceInitia…
Browse files Browse the repository at this point in the history
…lizer
  • Loading branch information
bmac committed Jun 15, 2015
1 parent 7b2c70d commit 1a4cac0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 37 deletions.
37 changes: 29 additions & 8 deletions packages/ember-data/lib/initializers/store.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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";
Expand All @@ -17,15 +18,7 @@ export default function initializeStore(registry, application) {
registry.optionsForType('serializer', { singleton: false });
registry.optionsForType('adapter', { singleton: false });

// This will get deprecated later in the instace
// initializer. However we register it here so we have access to
// application.Store in the instance initializer.
if (application && application.Store) {
registry.register('store:application', application.Store);
}

// allow older names to be looked up

var proxy = new ContainerProxy(registry);
proxy.registerDeprecations([
{ deprecated: 'serializer:_default', valid: 'serializer:-default' },
Expand All @@ -40,4 +33,32 @@ export default function initializeStore(registry, application) {

registry.register('adapter:-json-api', JSONAPIAdapter);
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 {

This comment has been minimized.

Copy link
@ppcano

ppcano Jun 23, 2015

Contributor

@bmac shouldn't check the store registration?

else if (!registry.has('service:store') {
  registry.register('service:store', application && application.Store || Store);
}
registry.register('service:store', application && application.Store || Store);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import Store from "ember-data/system/store";
import ContainerProxy from "ember-data/system/container-proxy";

/**
Configures a registry for use with an Ember-Data
store.
Expand Down Expand Up @@ -29,30 +26,5 @@ export default function initializeStoreService(applicationOrRegistry) {
}

// Eagerly generate the store so defaultStore is populated.
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 = container.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 = container.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 {
registry.register('service:store', Store);
}
container.lookup('service:store');
}

0 comments on commit 1a4cac0

Please sign in to comment.