Skip to content

Commit

Permalink
Add backwards compatibility for customs store's defined in app/store.js.
Browse files Browse the repository at this point in the history
Recommend people always use app/services/store.js to prevent duplicate stores.
  • Loading branch information
bmac committed Jun 10, 2015
1 parent 19fa1d0 commit 5e5e382
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 18 deletions.
6 changes: 3 additions & 3 deletions packages/ember-data/lib/initializers/store-injections.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@param {Ember.Registry} registry
*/
export default function initializeStoreInjections(registry) {
registry.injection('controller', 'store', 'store:application');
registry.injection('route', 'store', 'store:application');
registry.injection('data-adapter', 'store', 'store:application');
registry.injection('controller', 'store', 'service:store');
registry.injection('route', 'store', 'service:store');
registry.injection('data-adapter', 'store', 'service:store');
}
8 changes: 4 additions & 4 deletions packages/ember-data/lib/initializers/store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {JSONSerializer, RESTSerializer} from "ember-data/serializers";
import {RESTAdapter} from "ember-data/adapters";
import ContainerProxy from "ember-data/system/container-proxy";
import Store from "ember-data/system/store";

/**
Configures a registry for use with an Ember-Data
Expand All @@ -18,16 +17,17 @@ export default function initializeStore(registry, application) {
registry.optionsForType('serializer', { singleton: false });
registry.optionsForType('adapter', { singleton: false });

registry.register('store:application', application && application.Store || Store);
if (application && application.Store) {
registry.register('store:main', application.Store);
}

// 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' },
{ deprecated: 'store:main', valid: 'store:application' }
{ deprecated: 'adapter:_rest', valid: 'adapter:-rest' }
]);

// new go forward paths
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Store from "ember-data/system/store";
/**
Configures a registry for use with an Ember-Data
store.
Expand All @@ -24,7 +25,22 @@ export default function initializeStoreService(applicationOrRegistry) {
container = registry;
}
}

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

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');
}

if (store) {
registry.register('service:store', store, { instantiate: false });
} else {
registry.register('service:store', Store);
}
}
4 changes: 2 additions & 2 deletions packages/ember-data/tests/integration/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var app, App, container;
*/

function getStore() {
return lookup('store:application');
return lookup('service:store');
}

function lookup(thing) {
Expand Down Expand Up @@ -69,7 +69,7 @@ test("registering App.Store is deprecated but functional", function() {
'has been deprecated. Please use `App.ApplicationStore` instead.');

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

var fooController = lookup('controller:foo');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module('integration/backwards-compat/non-dasherized-lookups - non dasherized loo
name: DS.attr()
});
});
store = App.__container__.lookup('store:application');
store = App.__container__.lookup('service:store');
},
teardown: function() {
run(App, 'destroy');
Expand Down Expand Up @@ -67,7 +67,7 @@ module('integration/backwards-compat/non-dasherized-lookups - non dasherized loo
postNotes: DS.hasMany('post_note')
});
});
store = App.__container__.lookup('store:application');
store = App.__container__.lookup('service:store');
},

teardown: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module("DS.DebugAdapter", {

});

store = App.__container__.lookup('store:application');
store = App.__container__.lookup('service:store');
debugAdapter = App.__container__.lookup('data-adapter:main');

debugAdapter.reopen({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ test("embedded records should be created in multiple stores", function() {

run(function() {
json_main = serializer_main.extractSingle(env.store, env.store.modelFor('home-planet'), json_hash_main);
equal(env.store.hasRecordForId('super-villain', "1"), true, "superVillain should exist in store:application");
equal(env.store.hasRecordForId('super-villain', "1"), true, "superVillain should exist in service:store");
});

run(function() {
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-data/tests/integration/setup-container-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module("integration/setup-container - Setting up a container", {
});

test("The store should be registered into a container.", function() {
ok(container.lookup('store:application') instanceof Store, "the custom store is instantiated");
ok(container.lookup('service:store') instanceof Store, "the custom store is instantiated");
});

test("The store should be registered into the container as a service.", function() {
Expand Down Expand Up @@ -86,9 +86,9 @@ test("serializers are not returned as singletons - each lookup should return a d
notEqual(serializer1, serializer2);
});

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

0 comments on commit 5e5e382

Please sign in to comment.