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

Remove support for deprecated .container property on objects. #15192

Merged
merged 1 commit into from
May 1, 2017
Merged
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
58 changes: 1 addition & 57 deletions packages/container/lib/container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals Proxy */
import { assert, deprecate } from 'ember-debug';
import { DEBUG } from 'ember-env-flags';
/* globals Proxy */
import {
dictionary,
symbol,
Expand Down Expand Up @@ -35,7 +35,6 @@ export default function Container(registry, options) {
this.factoryCache = dictionary(options && options.factoryCache ? options.factoryCache : null);
this.factoryManagerCache = dictionary(options && options.factoryManagerCache ? options.factoryManagerCache : null);
this.validationCache = dictionary(options && options.validationCache ? options.validationCache : null);
this._fakeContainerToInject = buildFakeContainerWithDeprecations(this);
this[CONTAINER_OVERRIDE] = undefined;
this.isDestroyed = false;
}
Expand Down Expand Up @@ -390,8 +389,6 @@ function deprecatedFactoryFor(container, fullName, options = {}) {

let injectedFactory = factory.extend(injections);

// TODO - remove all `container` injections when Ember reaches v3.0.0
injectDeprecatedContainer(injectedFactory.prototype, container);
injectedFactory.reopenClass(factoryInjections);

if (factory && typeof factory._onLookup === 'function') {
Expand Down Expand Up @@ -484,29 +481,6 @@ function factoryInjectionsFor(container, fullName) {
return factoryInjections;
}

const INJECTED_DEPRECATED_CONTAINER_DESC = {
configurable: true,
enumerable: false,
get() {
deprecate('Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.', false, { id: 'ember-application.injected-container', until: '2.13.0', url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access' });
return this[CONTAINER_OVERRIDE] || getOwner(this).__container__;
},

set(value) {
deprecate(`Providing the \`container\` property to ${this} is deprecated. Please use \`Ember.setOwner\` or \`owner.ownerInjection()\` instead to provide an owner to the instance being created.`, false, { id: 'ember-application.injected-container', until: '2.13.0', url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access' });

this[CONTAINER_OVERRIDE] = value;

return value;
}
};

// TODO - remove when Ember reaches v3.0.0
function injectDeprecatedContainer(object, container) {
if ('container' in object) { return; }
Object.defineProperty(object, 'container', INJECTED_DEPRECATED_CONTAINER_DESC);
}

function destroyDestroyables(container) {
let cache = container.cache;
let keys = Object.keys(cache);
Expand Down Expand Up @@ -540,31 +514,6 @@ function resetMember(container, fullName) {
}
}

export function buildFakeContainerWithDeprecations(container) {
let fakeContainer = {};
let propertyMappings = {
lookup: 'lookup',
lookupFactory: '_lookupFactory'
};

for (let containerProperty in propertyMappings) {
fakeContainer[containerProperty] = buildFakeContainerFunction(container, containerProperty, propertyMappings[containerProperty]);
}

return fakeContainer;
}

function buildFakeContainerFunction(container, containerProperty, ownerProperty) {
return function () {
deprecate(`Using the injected \`container\` is deprecated. Please use the \`getOwner\` helper to access the owner of this object and then call \`${ownerProperty}\` instead.`, false, {
id: 'ember-application.injected-container',
until: '2.13.0',
url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access'
});
return container[containerProperty](...arguments);
};
}

class DeprecatedFactoryManager {
constructor(container, factory, fullName) {
this.container = container;
Expand Down Expand Up @@ -626,11 +575,6 @@ class FactoryManager {
throw new Error(`Failed to create an instance of '${this.normalizedName}'. Most likely an improperly defined class or` + ` an invalid module export.`);
}

let prototype = this.class.prototype;
if (prototype) {
injectDeprecatedContainer(prototype, this.container);
}

// required to allow access to things like
// the customized toString, _debugContainerKey,
// owner, etc. without a double extend and without
Expand Down
3 changes: 1 addition & 2 deletions packages/container/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ The public API, specified on the application namespace should be considered the

export { default as Registry, privatize } from './registry';
export {
default as Container,
buildFakeContainerWithDeprecations
default as Container
} from './container';
40 changes: 0 additions & 40 deletions packages/container/tests/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,46 +552,6 @@ QUnit.test('An object with its owner pre-set should be returned from ownerInject
equal(result[OWNER], owner, 'owner is properly included');
});

QUnit.test('A deprecated `container` property is appended to every object instantiated from an extendable factory', function() {
let owner = { };
let registry = new Registry();
let container = owner.__container__ = registry.container({ owner });
let PostController = factory();
registry.register('controller:post', PostController);
let postController = container.lookup('controller:post');

expectDeprecation(() => {
get(postController, 'container');
}, 'Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.');

expectDeprecation(() => {
let c = postController.container;
strictEqual(c, container);
}, 'Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.');
});

QUnit.test('An extendable factory can provide `container` upon create, with a deprecation', function(assert) {
let registry = new Registry();
let container = registry.container();

registry.register('controller:post', factory());

let PostController = lookupFactory('controller:post', container);

let postController;

expectDeprecation(() => {
postController = PostController.create({
container: 'foo'
});
}, /Providing the \`container\` property to .+ is deprecated. Please use \`Ember.setOwner\` or \`owner.ownerInjection\(\)\` instead to provide an owner to the instance being created/);

expectDeprecation(() => {
let c = postController.container;
assert.equal(c, 'foo', 'the `container` provided to `.create`was used');
}, 'Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.');
});

QUnit.test('lookupFactory passes options through to expandlocallookup', function(assert) {
let registry = new Registry();
let container = registry.container();
Expand Down