Skip to content

Commit

Permalink
[BUGFIX beta] Remove initializer deprecations for Ember 2.1.0+.
Browse files Browse the repository at this point in the history
As of Ember 2.1.0 initializers should receive a single argument (the
application), and that object has most of the public API of the previous
first argument (`register`, `optionsForType`, etc).

To support older initializers, any initializer written that expects 2
arguments receives a deprecation.  This fixes the argument arity to
prevent deprecations.
  • Loading branch information
rwjblue committed Aug 17, 2015
1 parent ce103da commit a0fdeea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
15 changes: 12 additions & 3 deletions packages/ember-data/lib/initializers/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ import Store from "ember-data/system/store";
import { JSONAPISerializer, JSONSerializer, RESTSerializer } from "ember-data/serializers";
import { JSONAPIAdapter, RESTAdapter } from "ember-data/adapters";

function has(applicationOrRegistry, fullName) {
if (applicationOrRegistry.has) {
// < 2.1.0
return applicationOrRegistry.has(fullName);
} else {
// 2.1.0+
return applicationOrRegistry.hasRegistration(fullName);
}
}

/**
Configures a registry for use with an Ember-Data
store. Accepts an optional namespace argument.
@method initializeStore
@param {Ember.Registry} registry
@param {Object} [application] an application namespace
*/
export default function initializeStore(registry, application) {
export default function initializeStore(registry) {
registry.optionsForType('serializer', { singleton: false });
registry.optionsForType('adapter', { singleton: false });

Expand All @@ -22,7 +31,7 @@ export default function initializeStore(registry, application) {
registry.register('serializer:-json-api', JSONAPISerializer);


if (!registry.has('service:store')) {
if (has(registry, 'service:store')) {
registry.register('service:store', Store);
}
}
14 changes: 5 additions & 9 deletions packages/ember-data/lib/setup-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import initializeTransforms from 'ember-data/initializers/transforms';
import initializeStoreInjections from 'ember-data/initializers/store-injections';
import initializeDataAdapter from 'ember-data/initializers/data-adapter';

export default function setupContainer(registry, application) {
// application is not a required argument. This ensures
// testing setups can setup a container without booting an
// entire ember application.

initializeDataAdapter(registry, application);
initializeTransforms(registry, application);
initializeStoreInjections(registry, application);
initializeStore(registry, application);
export default function setupContainer(application) {
initializeDataAdapter(application);
initializeTransforms(application);
initializeStoreInjections(application);
initializeStore(application);
}

0 comments on commit a0fdeea

Please sign in to comment.