forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX beta] Expose ownerInjection method on ContainerProxy.
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' } ); ```
- Loading branch information
Showing
4 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/ember-runtime/tests/mixins/container_proxy_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { OWNER } from 'container/owner'; | ||
import Registry from 'container/registry'; | ||
import Container from 'container/container'; | ||
import ContainerProxy from 'ember-runtime/mixins/container_proxy'; | ||
import EmberObject from 'ember-runtime/system/object'; | ||
|
||
QUnit.module('ember-runtime/mixins/container_proxy', { | ||
setup() { | ||
this.Owner = EmberObject.extend(ContainerProxy); | ||
this.instance = this.Owner.create(); | ||
|
||
let registry = new Registry(); | ||
|
||
this.instance.__container__ = new Container(registry, { | ||
owner: this.instance | ||
}); | ||
} | ||
}); | ||
|
||
QUnit.test('provides ownerInjection helper method', function(assert) { | ||
let result = this.instance.ownerInjection(); | ||
|
||
assert.equal(result[OWNER], this.instance, 'returns an object with the OWNER symbol'); | ||
}); |