feat(core): initial API work for tree shakable injectors - #20850
tinayuangao wants to merge 2 commits into
Conversation
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
|
You can preview 408eaba at https://pr20850-408eaba.ngbuilds.io/. |
|
You can preview 25c7788 at https://pr20850-25c7788.ngbuilds.io/. |
e772936 to
b4fd66b
Compare
|
You can preview e772936 at https://pr20850-e772936.ngbuilds.io/. |
|
You can preview b4fd66b at https://pr20850-b4fd66b.ngbuilds.io/. |
|
You can preview d6dad71 at https://pr20850-d6dad71.ngbuilds.io/. |
|
You can preview a59b047 at https://pr20850-a59b047.ngbuilds.io/. |
|
You can preview 6fd9547 at https://pr20850-6fd9547.ngbuilds.io/. |
There was a problem hiding this comment.
this will end up as public API, and I don't think we want to point to the design doc from there. Maybe remove the design doc link?
There was a problem hiding this comment.
move this TS issue into a comment, so that it is not part of the Public API.
There was a problem hiding this comment.
I think we need to process this in different order.
Given
@NgModule({
provides: [{provide: Foo, useValue: 'fooChild'}]
})
class ModuleChild {}
@NgModule({
provides: [{provide: Foo, useValue: 'fooParent'}]
imports: [ModuleChild]
})
class ModuleParent {}
In the above case the ModuleParent's providers should override that of ModuleChild, which means that Foo should be fooParent not fooChild. The way it is being processed now the imports are being overwritten.
So I think we need to process providers first and than process providers.
Also please add a tests which demonstrates it.
There was a problem hiding this comment.
can you add a tests which shows that providerOrInjectorDefType.ngInjectorDef.type gets instantiated eagerly? Which means that we will probably have to collect all of them into some array and than when the injector is done constructing we need to iterate over the array and retrieve all of the types so that they get treated.
There was a problem hiding this comment.
using find is not as performant as doing a for loop over the array. Since retrieval is time sensitive could you use a for loop.
Also we should be looking up the token only if we don't have record since otherwise we are wasting time. Please move closer to the place of use.
There was a problem hiding this comment.
Also add record here so that we can cache the parent value. This will also increase performance.
There was a problem hiding this comment.
I don't think ngModule will ever be not defined. So this check is not needed.
There was a problem hiding this comment.
What is the TODO comment for?
There was a problem hiding this comment.
- use
Injector.createsince that is the public API. - Until that TS bug gets fixed we should change the public API to take
Typeso that we can avoid these casts.
There was a problem hiding this comment.
We need to export all of the SenProviders as well
a024bb2 to
38258e1
Compare
|
You can preview a024bb2 at https://pr20850-a024bb2.ngbuilds.io/. |
|
You can preview 38258e1 at https://pr20850-38258e1.ngbuilds.io/. |
|
You can preview 7bd76e1 at https://pr20850-7bd76e1.ngbuilds.io/. |
|
You can preview cf724a4 at https://pr20850-cf724a4.ngbuilds.io/. |
|
You can preview 8e1cd1c at https://pr20850-8e1cd1c.ngbuilds.io/. |
|
I can't understand title. I have a little knowledge about |
|
@LinboLen It make dropping unused injectables(services) possible for size saving purpose. (In combining with proper JavaScript bundler) |
|
You can preview 4f5c60c at https://pr20850-4f5c60c.ngbuilds.io/. |
|
You can preview 5b0759a at https://pr20850-5b0759a.ngbuilds.io/. |
|
You can preview 7b02a73 at https://pr20850-7b02a73.ngbuilds.io/. |
|
You can preview d5e098e at https://pr20850-d5e098e.ngbuilds.io/. |
|
We should merge this only after 5.2.0 is cut on Wednesday. |
|
You can preview dbf6255 at https://pr20850-dbf6255.ngbuilds.io/. |
|
Hi @tinayuangao! This PR has merge conflicts due to recent upstream merges. |
|
Superseded by #22005. |
|
Closing this PR since @alxhub has taken over. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Current
Injectabledon't take any parameters.What is the new behavior?
Injectablecan be used withNgModuleand providerDoes this PR introduce a breaking change?
Other information