diff --git a/addon/-private/ember-initializer.js b/addon/-private/ember-initializer.js deleted file mode 100644 index 5a0c19cb3ed..00000000000 --- a/addon/-private/ember-initializer.js +++ /dev/null @@ -1,80 +0,0 @@ -import Ember from 'ember'; -import setupContainer from 'ember-data/-private/setup-container'; -import initializeStoreService from 'ember-data/-private/instance-initializers/initialize-store-service'; - - -var K = Ember.K; - -/** - @module ember-data -*/ - -/* - - This code initializes Ember-Data onto an Ember application. - - If an Ember.js developer defines a subclass of DS.Store on their application, - as `App.StoreService` (or via a module system that resolves to `service:store`) - this code will automatically instantiate it and make it available on the - router. - - Additionally, after an application's controllers have been injected, they will - each have the store made available to them. - - For example, imagine an Ember.js application with the following classes: - - App.StoreService = DS.Store.extend({ - adapter: 'custom' - }); - - App.PostsController = Ember.ArrayController.extend({ - // ... - }); - - When the application is initialized, `App.ApplicationStore` will automatically be - instantiated, and the instance of `App.PostsController` will have its `store` - property set to that instance. - - Note that this code will only be run if the `ember-application` package is - loaded. If Ember Data is being used in an environment other than a - typical application (e.g., node.js where only `ember-runtime` is available), - this code will be ignored. -*/ - -Ember.onLoad('Ember.Application', function(Application) { - - Application.initializer({ - name: "ember-data", - initialize: setupContainer - }); - - Application.instanceInitializer({ - name: "ember-data", - initialize: initializeStoreService - }); - - // Deprecated initializers to satisfy old code that depended on them - Application.initializer({ - name: "store", - after: "ember-data", - initialize: K - }); - - Application.initializer({ - name: "transforms", - before: "store", - initialize: K - }); - - Application.initializer({ - name: "data-adapter", - before: "store", - initialize: K - }); - - Application.initializer({ - name: "injectStore", - before: "store", - initialize: K - }); -}); diff --git a/addon/index.js b/addon/index.js index e922fd73867..241ed273ffa 100644 --- a/addon/index.js +++ b/addon/index.js @@ -82,8 +82,8 @@ import { } from "ember-data/-private/transforms"; import {hasMany, belongsTo} from "ember-data/-private/system/relationships"; -import "ember-data/-private/ember-initializer"; import setupContainer from "ember-data/-private/setup-container"; +import initializeStoreService from 'ember-data/-private/instance-initializers/initialize-store-service'; import ContainerProxy from "ember-data/-private/system/container-proxy"; import Relationship from "ember-data/-private/system/relationships/state/relationship"; @@ -148,6 +148,7 @@ DS.Relationship = Relationship; DS.ContainerProxy = ContainerProxy; DS._setupContainer = setupContainer; +DS._initializeStoreService = initializeStoreService; Object.defineProperty(DS, 'normalizeModelName', { enumerable: true, diff --git a/app/initializers/ember-data.js b/app/initializers/ember-data.js index 8c6853d299d..7abc97caadf 100644 --- a/app/initializers/ember-data.js +++ b/app/initializers/ember-data.js @@ -1,5 +1,37 @@ import setupContainer from 'ember-data/-private/setup-container'; +/* + + This code initializes Ember-Data onto an Ember application. + + If an Ember.js developer defines a subclass of DS.Store on their application, + as `App.StoreService` (or via a module system that resolves to `service:store`) + this code will automatically instantiate it and make it available on the + router. + + Additionally, after an application's controllers have been injected, they will + each have the store made available to them. + + For example, imagine an Ember.js application with the following classes: + + App.StoreService = DS.Store.extend({ + adapter: 'custom' + }); + + App.PostsController = Ember.ArrayController.extend({ + // ... + }); + + When the application is initialized, `App.ApplicationStore` will automatically be + instantiated, and the instance of `App.PostsController` will have its `store` + property set to that instance. + + Note that this code will only be run if the `ember-application` package is + loaded. If Ember Data is being used in an environment other than a + typical application (e.g., node.js where only `ember-runtime` is available), + this code will be ignored. +*/ + export default { name: 'ember-data', initialize: setupContainer diff --git a/lib/javascripts.js b/lib/javascripts.js index 5ea125386f0..ae56f758d02 100644 --- a/lib/javascripts.js +++ b/lib/javascripts.js @@ -107,13 +107,15 @@ function collapse(tree, outputFileName) { var emberDataShimsPath = path.join(__dirname, 'ember-data-shims.js'); var emberDataShims = fs.readFileSync(emberDataShimsPath, { encoding: 'utf8' }); + var emberDataInitialierPath = path.join(__dirname, '../tests/ember-data-initializers.js'); + var emberDataInitialier = fs.readFileSync(emberDataInitialierPath, { encoding: 'utf8' }); var withLoader = merge([tree, loader, license, emberShim]); return concat(withLoader, { inputFiles: ['license.js', 'loader.js', '**/*.js'], outputFile: '/' + outputFileName, header: '(function(){ \n"use strict";\n', - footer: '\nrequire("ember-data");\n})();\n' + emberDataShims + footer: '\nrequire("ember-data");\n})();\n' + emberDataShims + emberDataInitialier }); } diff --git a/tests/ember-data-initializers.js b/tests/ember-data-initializers.js new file mode 100644 index 00000000000..0dc930de9c4 --- /dev/null +++ b/tests/ember-data-initializers.js @@ -0,0 +1,42 @@ +;(function() { + /* globals Ember */ + /* globals DS */ + var K = Ember.K; + Ember.onLoad('Ember.Application', function(Application) { + + Application.initializer({ + name: "ember-data", + initialize: DS._setupContainer + }); + + Application.instanceInitializer({ + name: "ember-data", + initialize: DS._initializeStoreService + }); + + // Deprecated initializers to satisfy old code that depended on them + Application.initializer({ + name: "store", + after: "ember-data", + initialize: K + }); + + Application.initializer({ + name: "transforms", + before: "store", + initialize: K + }); + + Application.initializer({ + name: "data-adapter", + before: "store", + initialize: K + }); + + Application.initializer({ + name: "injectStore", + before: "store", + initialize: K + }); + }); +})(); diff --git a/tests/test-helper.js b/tests/test-helper.js index bf6077bcb49..902dbaa3d22 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -15,6 +15,7 @@ import { } from 'dummy/tests/helpers/warns'; import addEmberAssertions from 'dummy/tests/helpers/ember-assertions'; import Ember from 'ember'; +import './ember-data-initializers'; setResolver(resolver);