-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
d4c02aa
to
3f89eb9
Compare
3065c44
to
27a3b80
Compare
27a3b80
to
bd1c638
Compare
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. |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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
)
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.
bd1c638
to
28aa862
Compare
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'ssrc
tree can invoke components and helpers in that tree because it has asource
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:
expandLocalLookup
to for the resolution of local item instead of a new argument toresolve
on resolvers.resolverCacheKey
, no longer needed.