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

[CLEANUP beta] Remove deprecated registry behaviour #11756

Closed
Closed
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
70 changes: 1 addition & 69 deletions packages/container/lib/registry.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import Ember from 'ember-metal/core'; // Ember.assert
import isEnabled from 'ember-metal/features';
import dictionary from 'ember-metal/dictionary';
import { assign } from 'ember-metal/merge';
import Container from './container';

var VALID_FULL_NAME_REGEXP = /^[^:]+.+:[^:]+$/;

var instanceInitializersFeatureEnabled;
if (isEnabled('ember-application-instance-initializers')) {
instanceInitializersFeatureEnabled = true;
}

/**
A registry used to store factory and option information keyed
by type.
Expand Down Expand Up @@ -133,18 +127,6 @@ Registry.prototype = {
*/
_typeOptions: null,

/**
The first container created for this registry.

This allows deprecated access to `lookup` and `lookupFactory` to avoid
breaking compatibility for Ember 1.x initializers.

@private
@property _defaultContainer
@type Container
*/
_defaultContainer: null,

/**
Creates a container based on this registry.

Expand All @@ -154,52 +136,7 @@ Registry.prototype = {
@return {Container} created container
*/
container(options) {
var container = new Container(this, options);

// 2.0TODO - remove `registerContainer`
this.registerContainer(container);

return container;
},

/**
Register the first container created for a registery to allow deprecated
access to its `lookup` and `lookupFactory` methods to avoid breaking
compatibility for Ember 1.x initializers.

2.0TODO: Remove this method. The bookkeeping is only needed to support
deprecated behavior.

@private
@param {Container} newly created container
*/
registerContainer(container) {
if (!this._defaultContainer) {
this._defaultContainer = container;
}
if (this.fallback) {
this.fallback.registerContainer(container);
}
},

lookup(fullName, options) {
Ember.assert('Create a container on the registry (with `registry.container()`) before calling `lookup`.', this._defaultContainer);

if (instanceInitializersFeatureEnabled) {
Ember.deprecate('`lookup` was called on a Registry. The `initializer` API no longer receives a container, and you should use an `instanceInitializer` to look up objects from the container.', false, { url: 'http://emberjs.com/guides/deprecations#toc_deprecate-access-to-instances-in-initializers' });
}

return this._defaultContainer.lookup(fullName, options);
},

lookupFactory(fullName) {
Ember.assert('Create a container on the registry (with `registry.container()`) before calling `lookupFactory`.', this._defaultContainer);

if (instanceInitializersFeatureEnabled) {
Ember.deprecate('`lookupFactory` was called on a Registry. The `initializer` API no longer receives a container, and you should use an `instanceInitializer` to look up objects from the container.', false, { url: 'http://emberjs.com/guides/deprecations#toc_deprecate-access-to-instances-in-initializers' });
}

return this._defaultContainer.lookupFactory(fullName);
return new Container(this, options);
},

/**
Expand Down Expand Up @@ -457,11 +394,6 @@ Registry.prototype = {
}
},

option(fullName, optionName) {
Ember.deprecate('`Registry.option()` has been deprecated. Call `Registry.getOption()` instead.');
return this.getOption(fullName, optionName);
},

/**
Used only via `injection`.

Expand Down
3 changes: 1 addition & 2 deletions packages/container/tests/registry_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ QUnit.test('factory for non extendables resolves are cached', function() {
deepEqual(resolveWasCalled, ['foo:post']);
});

QUnit.test('registry.container creates an associated container', function() {
QUnit.test('registry.container creates a container', function() {
var registry = new Registry();
var PostController = factory();
registry.register('controller:post', PostController);
Expand All @@ -269,7 +269,6 @@ QUnit.test('registry.container creates an associated container', function() {
var postController = container.lookup('controller:post');

ok(postController instanceof PostController, 'The lookup is an instance of the registered factory');
strictEqual(registry._defaultContainer, container, '_defaultContainer is set to the first created container and used for Ember 1.x Container compatibility');
});

QUnit.test('`resolve` can be handled by a fallback registry', function() {
Expand Down
31 changes: 13 additions & 18 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,15 @@ var Application = Namespace.extend({
run.join(this, handleReset);
},


/**
@private
@method instanceInitializer
*/
instanceInitializer(options) {
this.constructor.instanceInitializer(options);
},

/**
@private
@method runInitializers
Expand All @@ -681,13 +690,7 @@ var Application = Namespace.extend({
var App = this;
this._runInitializer('initializers', function(name, initializer) {
Ember.assert('No application initializer named \'' + name + '\'', !!initializer);

if (isEnabled('ember-application-initializer-context')) {
initializer.initialize(registry, App);
} else {
var ref = initializer.initialize;
ref(registry, App);
}
initializer.initialize(registry, App);
});
},

Expand Down Expand Up @@ -793,17 +796,9 @@ var Application = Namespace.extend({
}
});

if (isEnabled('ember-application-instance-initializers')) {
Application.reopen({
instanceInitializer(options) {
this.constructor.instanceInitializer(options);
}
});

Application.reopenClass({
instanceInitializer: buildInitializerMethod('instanceInitializers', 'instance initializer')
});
}
Application.reopenClass({
instanceInitializer: buildInitializerMethod('instanceInitializers', 'instance initializer')
});

if (isEnabled('ember-application-visit')) {
Application.reopen({
Expand Down
77 changes: 14 additions & 63 deletions packages/ember-application/tests/system/initializers_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Ember from 'ember-metal/core';
import isEnabled from 'ember-metal/features';
import run from 'ember-metal/run_loop';
import Application from 'ember-application/system/application';
import jQuery from 'ember-views/system/jquery';
Expand Down Expand Up @@ -333,70 +332,22 @@ QUnit.test('initializers are per-app', function() {
});
});

if (isEnabled('ember-application-initializer-context')) {
QUnit.test('initializers should be executed in their own context', function() {
expect(1);
var MyApplication = Application.extend();

MyApplication.initializer({
name: 'coolBabeInitializer',
myProperty: 'coolBabe',
initialize(registry, application) {
equal(this.myProperty, 'coolBabe', 'should have access to its own context');
}
});

run(function() {
app = MyApplication.create({
router: false,
rootElement: '#qunit-fixture'
});
});
});
}

if (isEnabled('ember-application-instance-initializers')) {
QUnit.test('initializers should throw a deprecation warning when performing a lookup on the registry', function() {
expect(1);

var MyApplication = Application.extend();

MyApplication.initializer({
name: 'initializer',
initialize(registry, application) {
registry.lookup('router:main');
}
});
QUnit.test('initializers should be executed in their own context', function() {
expect(1);
var MyApplication = Application.extend();

expectDeprecation(function() {
run(function() {
app = MyApplication.create({
router: false,
rootElement: '#qunit-fixture'
});
});
}, /`lookup` was called on a Registry\. The `initializer` API no longer receives a container, and you should use an `instanceInitializer` to look up objects from the container\./);
MyApplication.initializer({
name: 'coolBabeInitializer',
myProperty: 'coolBabe',
initialize(registry, application) {
equal(this.myProperty, 'coolBabe', 'should have access to its own context');
}
});

QUnit.test('initializers should throw a deprecation warning when performing a factory lookup on the registry', function() {
expect(1);

var MyApplication = Application.extend();

MyApplication.initializer({
name: 'initializer',
initialize(registry, application) {
registry.lookupFactory('application:controller');
}
run(function() {
app = MyApplication.create({
router: false,
rootElement: '#qunit-fixture'
});

expectDeprecation(function() {
run(function() {
app = MyApplication.create({
router: false,
rootElement: '#qunit-fixture'
});
});
}, /`lookupFactory` was called on a Registry\. The `initializer` API no longer receives a container, and you should use an `instanceInitializer` to look up objects from the container\./);
});
}
});
Loading