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

Register service:store in an initializer instead of an instanceInitia… #3349

Merged
merged 1 commit into from
Jun 16, 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
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 {
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');
}