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] Expose ownerInjection method on ContainerProxy. #12629

Merged
merged 1 commit into from
Nov 20, 2015

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Nov 20, 2015

The ember-container-inject-owner feature provides a public API for accessing various container/registry functions. Unfortunately, creating an instance that has access to the same owner is a somewhat annoying API compared to what we would do today.

In Ember 2.2 you would often do this (though it still uses private API):

User.create({
 container: this.container,
 username: 'John'
});

But in 2.3.0-beta.1 to do roughly the same thing, you would have to do:

var options = { username: 'John' };
setOwner(options, getOwner(this));

User.create(options);

This is definitely less ergonomic for a perfectly supported case. With the changes added here, you would use the following:

User.create(
 getOwner(this).ownerInjection(),
 { username: 'John' }
);

/cc @dgeb (as we previously discussed)

@@ -519,6 +519,16 @@ QUnit.test('Lazy injection validations are cached', function() {
container.lookup('apple:main');
});

QUnit.test('A registered factory is returned from lookupFactory', function() {
Copy link
Member

Choose a reason for hiding this comment

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

This test title should reference ownerInjection. Perhaps "An object with its owner pre-set should be returned from ownerInjection".

Copy link
Member Author

Choose a reason for hiding this comment

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

LOL, copy pasta

@dgeb
Copy link
Member

dgeb commented Nov 20, 2015

LGTM other than that test title 👍

The `ember-container-inject-owner` feature provides a public API for
accessing various container/registry functions. Unfortunately, creating
an instance that has access to the same owner is a somewhat annoying
API compared to what we would do today.

In Ember 2.2 you would often do this (though it still uses private API):

```js
User.create({
 container: this.container,
 username: 'John'
});
```

But in 2.3.0-beta.1 to do roughly the same thing, you would have to do:

```js
var options = { username: 'John' };
setOwner(options, getOwner(this));

User.create(options);
```

This is definitely less ergonomic for a perfectly supported case.  With
the changes added here, you would use the following:

```js
User.create(
 getOwner(this).ownerInjection(),
 { username: 'John' }
);
```
rwjblue added a commit that referenced this pull request Nov 20, 2015
[BUGFIX beta] Expose ownerInjection method on ContainerProxy.
@rwjblue rwjblue merged commit cfed401 into emberjs:master Nov 20, 2015
@rwjblue rwjblue deleted the add-owner-injection branch November 20, 2015 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants