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

[BUGFIX beta] Avoid storing container on the prototype. #15163

Merged
merged 1 commit into from
Apr 24, 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
4 changes: 2 additions & 2 deletions packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
dictionary,
symbol,
setOwner,
getOwner,
OWNER,
assign,
NAME_KEY,
Expand Down Expand Up @@ -521,7 +522,7 @@ const INJECTED_DEPRECATED_CONTAINER_DESC = {
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: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access' });
return this[CONTAINER_OVERRIDE];
return this[CONTAINER_OVERRIDE] || getOwner(this).__container__;
},

set(value) {
Expand All @@ -537,7 +538,6 @@ const INJECTED_DEPRECATED_CONTAINER_DESC = {
function injectDeprecatedContainer(object, container) {
if ('container' in object) { return; }
Object.defineProperty(object, 'container', INJECTED_DEPRECATED_CONTAINER_DESC);
object[CONTAINER_OVERRIDE] = container;
}

function destroyDestroyables(container) {
Expand Down
4 changes: 2 additions & 2 deletions packages/container/tests/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,9 @@ QUnit.test('An object with its owner pre-set should be returned from ownerInject
});

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 = registry.container();
let container = owner.__container__ = registry.container({ owner });
Copy link
Member Author

@rwjblue rwjblue Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - This is exactly what is done in "reality" outside of these unit tests. See EngineInstance code for confirmation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App instance didn't already have a ref to the container?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, I realize here owner is a stub for a unit test, ignore my comment.

let PostController = factory();
registry.register('controller:post', PostController);
let postController = container.lookup('controller:post');
Expand Down Expand Up @@ -741,4 +742,3 @@ QUnit.test('#factoryFor options passed to create clobber injections', (assert) =

assert.equal(instrance.ajax, 'fetch');
});