From c061ad4a24ea4f7dfbd23e44cc14cf185b214760 Mon Sep 17 00:00:00 2001 From: bmac Date: Fri, 12 Jun 2015 14:50:23 -0400 Subject: [PATCH] Support custom stores defined on the container as --- .../ember-data/lib/initializers/store-injections.js | 6 +++--- packages/ember-data/lib/initializers/store.js | 8 ++++---- .../initialize-store-service.js | 10 +++++++++- packages/ember-data/lib/main.js | 4 ++++ .../tests/integration/application-test.js | 4 ++-- .../backwards-compat/non-dasherized-lookups.js | 4 ++-- .../tests/integration/debug-adapter-test.js | 2 +- .../tests/integration/multiple_stores_test.js | 2 +- .../tests/integration/setup-container-test.js | 13 +------------ 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/packages/ember-data/lib/initializers/store-injections.js b/packages/ember-data/lib/initializers/store-injections.js index af907d0bd33..16dca7f409b 100644 --- a/packages/ember-data/lib/initializers/store-injections.js +++ b/packages/ember-data/lib/initializers/store-injections.js @@ -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', 'store:main'); + registry.injection('route', 'store', 'store:main'); + registry.injection('data-adapter', 'store', 'store:main'); } diff --git a/packages/ember-data/lib/initializers/store.js b/packages/ember-data/lib/initializers/store.js index e86832289b2..327ca307f40 100644 --- a/packages/ember-data/lib/initializers/store.js +++ b/packages/ember-data/lib/initializers/store.js @@ -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 @@ -18,7 +17,9 @@ 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:application', application.Store); + } // allow older names to be looked up @@ -26,8 +27,7 @@ export default function initializeStore(registry, application) { 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 diff --git a/packages/ember-data/lib/instance-initializers/initialize-store-service.js b/packages/ember-data/lib/instance-initializers/initialize-store-service.js index 638b2ed3939..54f6b962519 100644 --- a/packages/ember-data/lib/instance-initializers/initialize-store-service.js +++ b/packages/ember-data/lib/instance-initializers/initialize-store-service.js @@ -1,3 +1,4 @@ +import Store from "ember-data/system/store"; /** Configures a registry for use with an Ember-Data store. @@ -24,7 +25,14 @@ export default function initializeStoreService(applicationOrRegistry) { container = registry; } } + if (registry.has('store:application')) { + var customStoreFactory = container.lookupFactory('store:application'); + registry.register('store:main', customStoreFactory); + } else { + registry.register('store:main', Store); + } + // Eagerly generate the store so defaultStore is populated. - var store = container.lookup('store:application'); + var store = container.lookup('store:main'); registry.register('service:store', store, { instantiate: false }); } diff --git a/packages/ember-data/lib/main.js b/packages/ember-data/lib/main.js index d5a28b47a5a..09a6a1ae872 100644 --- a/packages/ember-data/lib/main.js +++ b/packages/ember-data/lib/main.js @@ -10,6 +10,10 @@ if (Ember.VERSION.match(/^1\.[0-7]\./)) { ". Please upgrade your version of Ember, then upgrade Ember Data"); } +if (Ember.VERSION.match(/^1\.12\.0/)) { + throw new Ember.Error("Ember Data does not work with Ember 1.12.0. Please upgrade to Ember 1.12.1 or higher."); +} + // support RSVP 2.x via resolve, but prefer RSVP 3.x's Promise.cast Ember.RSVP.Promise.cast = Ember.RSVP.Promise.cast || Ember.RSVP.resolve; diff --git a/packages/ember-data/tests/integration/application-test.js b/packages/ember-data/tests/integration/application-test.js index 1c523737724..31ffb01e93b 100644 --- a/packages/ember-data/tests/integration/application-test.js +++ b/packages/ember-data/tests/integration/application-test.js @@ -13,7 +13,7 @@ var app, App, container; */ function getStore() { - return lookup('store:application'); + return lookup('store:main'); } function lookup(thing) { @@ -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('store:main').get('isCustomButDeprecated'), "the custom store was instantiated"); }); var fooController = lookup('controller:foo'); diff --git a/packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups.js b/packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups.js index e026bea16d5..531f35da9e2 100644 --- a/packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups.js +++ b/packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups.js @@ -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('store:main'); }, teardown: function() { run(App, 'destroy'); @@ -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('store:main'); }, teardown: function() { diff --git a/packages/ember-data/tests/integration/debug-adapter-test.js b/packages/ember-data/tests/integration/debug-adapter-test.js index 34f7356628f..7ea659afc43 100644 --- a/packages/ember-data/tests/integration/debug-adapter-test.js +++ b/packages/ember-data/tests/integration/debug-adapter-test.js @@ -23,7 +23,7 @@ module("DS.DebugAdapter", { }); - store = App.__container__.lookup('store:application'); + store = App.__container__.lookup('store:main'); debugAdapter = App.__container__.lookup('data-adapter:main'); debugAdapter.reopen({ diff --git a/packages/ember-data/tests/integration/multiple_stores_test.js b/packages/ember-data/tests/integration/multiple_stores_test.js index 1156cae6e96..badc61087e4 100644 --- a/packages/ember-data/tests/integration/multiple_stores_test.js +++ b/packages/ember-data/tests/integration/multiple_stores_test.js @@ -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 store:main"); }); run(function() { diff --git a/packages/ember-data/tests/integration/setup-container-test.js b/packages/ember-data/tests/integration/setup-container-test.js index e8c85d2ea8c..724f6537bcc 100644 --- a/packages/ember-data/tests/integration/setup-container-test.js +++ b/packages/ember-data/tests/integration/setup-container-test.js @@ -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('store:main') instanceof Store, "the custom store is instantiated"); }); test("The store should be registered into the container as a service.", function() { @@ -86,17 +86,6 @@ 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() { - var deprecated; - var valid = container.lookup('store:application'); - expectDeprecation(function() { - deprecated = container.lookup('store:main'); - }); - - 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');