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

[Module Unification] Introduce source to injections #16240

Merged
merged 3 commits into from
Mar 4, 2018

Conversation

mixonic
Copy link
Member

@mixonic mixonic commented Feb 13, 2018

Ember templates use a source argument to the container. This hints where to look for "local lookup", and also what namespace to look in for a partial specifier. For example a template in an addon's src tree can invoke components and helpers in that tree because it has a source argument passed to lookups.

This introduces the same functionality for service injections. A service can now accept a source argument and its lookup will apply to the namespace of that file.

Additionally:

  • Use expandLocalLookup to for the resolution of local item instead of a new argument to resolve on resolvers.
  • Get rid of resolverCacheKey, no longer needed.

@mixonic mixonic changed the title Introduce source to injections [Module Unification] Introduce source to injections Feb 13, 2018
@mixonic mixonic force-pushed the injection-sources branch 12 times, most recently from 3065c44 to 27a3b80 Compare March 4, 2018 04:40
@mixonic mixonic force-pushed the injection-sources branch from 27a3b80 to bd1c638 Compare March 4, 2018 05:53
@mixonic
Copy link
Member Author

mixonic commented Mar 4, 2018

I think this is ready to go in. All the work is behind a feature flag. The implementation is in line with the Module Unification Namespaces RFC emberjs/rfcs#309

I'm going to look at rebasing #15967 on top of this.

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Only had a few minor tweaks / questions, but looks good to me...

@@ -35,5 +36,10 @@ function injectedPropertyGet(keyName) {
assert(`InjectedProperties should be defined with the inject computed property macros.`, desc && desc.type);
assert(`Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container.`, owner);

return owner.lookup(`${desc.type}:${desc.name || keyName}`);
let specifier = `${desc.type}:${desc.name || keyName}`;
if (desc.source) {
Copy link
Member

Choose a reason for hiding this comment

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

I don’t fully grok why we need this conditional. Seems to be that calling lookup like owner.lookup(specifier, { source: undefined }) (which is what would happen if desc.source is not present) would be fine. What am I missing?

* configuration (such as a singleton type that has local lookup).
*/
['@test Services can be injected with same name, one with source one without, and share an instance'](assert) {
let routeASource = 'service:src/ui/routes/route-a/controller';
Copy link
Member

Choose a reason for hiding this comment

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

Seems odd to have the source here be prefixed with service: (the actual type is controller)

mixonic added 2 commits March 4, 2018 08:05
Ember templates use a `source` argument to the container. This hints
where to look for "local lookup", and also what namespace to look in for
a partial specifier. For example a template in an addon's `src` tree can
invoke components and helpers in that tree becuase it has a `source`
argument passed to lookups.

This introduces the same functionality for service injections. A service
can now accept a `source` argument and its lookup will apply to the
namespace of that file.

Additionally, refactor away from using a `source` argument to the
`resolve` API of resolvers. Instead leveral the `expandLocalLookup` API
to pass the source and get an identifier that can be treated as
canonical for that factory.
@mixonic mixonic force-pushed the injection-sources branch from bd1c638 to 28aa862 Compare March 4, 2018 16:05
@mixonic mixonic merged commit 80c5127 into emberjs:master Mar 4, 2018
@mixonic mixonic deleted the injection-sources branch March 4, 2018 16:32
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