-
Notifications
You must be signed in to change notification settings - Fork 26.2k
feat: tree-shakeable providers API updates #22655
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
Conversation
You can preview 679fee0 at https://pr22655-679fee0.ngbuilds.io/. |
679fee0
to
ae6e61c
Compare
You can preview ae6e61c at https://pr22655-ae6e61c.ngbuilds.io/. |
ae6e61c
to
0210da8
Compare
You can preview 0210da8 at https://pr22655-0210da8.ngbuilds.io/. |
0210da8
to
57d4702
Compare
You can preview 57d4702 at https://pr22655-57d4702.ngbuilds.io/. |
57d4702
to
142c604
Compare
You can preview 142c604 at https://pr22655-142c604.ngbuilds.io/. |
142c604
to
4bbb8b3
Compare
You can preview 4bbb8b3 at https://pr22655-4bbb8b3.ngbuilds.io/. |
cdd555b
to
76207e5
Compare
You can preview 76207e5 at https://pr22655-76207e5.ngbuilds.io/. |
76207e5
to
5d277a6
Compare
You can preview 5d277a6 at https://pr22655-5d277a6.ngbuilds.io/. |
5d277a6
to
e4bbad3
Compare
You can preview e4bbad3 at https://pr22655-e4bbad3.ngbuilds.io/. |
e4bbad3
to
af9c32f
Compare
You can preview af9c32f at https://pr22655-af9c32f.ngbuilds.io/. |
packages/compiler/src/core.ts
Outdated
@@ -127,7 +127,7 @@ export interface ModuleWithProviders { | |||
providers?: Provider[]; | |||
} | |||
export interface Injectable { | |||
scope?: Type|any; | |||
providedIn?: Type|any; |
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.
Consider adding |'root'
. Since it is any
it is not necessary but it would be more clear that 'root'
is special.
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.
Done.
5cd6b0c
to
1649970
Compare
You can preview 5cd6b0c at https://pr22655-5cd6b0c.ngbuilds.io/. |
You can preview 1649970 at https://pr22655-1649970.ngbuilds.io/. |
1649970
to
227e098
Compare
Rename @Injectable({scope -> providedIn}). Instead of {providedIn: APP_ROOT_SCOPE}, accept {providedIn: 'root'}. Also, {providedIn: null} implies the injectable should not be added to any scope.
227e098
to
663f1dc
Compare
You can preview 227e098 at https://pr22655-227e098.ngbuilds.io/. |
You can preview 663f1dc at https://pr22655-663f1dc.ngbuilds.io/. |
@@ -71,7 +71,7 @@ export function _document(): any { | |||
@NgModule({ | |||
providers: [ | |||
BROWSER_SANITIZATION_PROVIDERS, | |||
{provide: APP_ROOT_SCOPE, useValue: true}, | |||
{provide: APP_ROOT, useValue: true}, |
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.
Is there another way to mark a module as root without relying on APP_ROOT
? I think the design would be nicer if this line would not exist.
We could test if we are root if:
- There is no parent
- The parent injector is NULL_INJECTOR
- The parent injector is PlatformRef injector?
Alternatively we could have the boostrap method call createModule with some extra argument to designate that it should be root injector.
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.
This is an internal implementation detail only (APP_ROOT
is not exposed to the user), so yes, we could have a different way of detecting it.
This current setup does have an advantage - because APP_ROOT
is tied to BrowserModule
in the existing system, it guarantees that the application-level services which Angular provides are in the "root scope" injector as well. This isn't necessarily the case if the user gets creative with injector structures.
@@ -47,7 +42,7 @@ export function moduleDef(providers: NgModuleProviderDef[]): NgModuleDefinition | |||
let isRoot: boolean = false; | |||
for (let i = 0; i < providers.length; i++) { | |||
const provider = providers[i]; | |||
if (provider.token === APP_ROOT_SCOPE) { | |||
if (provider.token === APP_ROOT) { |
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.
Is there another way to mark a module as root without relying on APP_ROOT
?
We could have the boostrap method call createModule with some extra argument to designate that it should be root injector.
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.
Answered above.
*/ | ||
export const APP_ROOT_SCOPE: Type<any> = new InjectionToken<boolean>( | ||
'The presence of this token marks an injector as being the root injector.') as any; | ||
export const APP_ROOT = new InjectionToken<boolean>( |
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 would like to get rid of APP_ROOT
. It is not public, but it sort of is since platform-browser has a special relationship with it. Which means that platform-browser is special and only it can create root injectors.
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 think this should be a separate discussion and should not block this PR which is blocking 6.0 RC. Since it is internal we can change the behavior before 6.0 final.
Rename @Injectable({scope -> providedIn}). Instead of {providedIn: APP_ROOT_SCOPE}, accept {providedIn: 'root'}. Also, {providedIn: null} implies the injectable should not be added to any scope. PR Close angular#22655
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. |
Rename @Injectable({scope -> providedIn}).
Instead of {providedIn: APP_ROOT_SCOPE}, accept {providedIn: 'root'}.
Also, {providedIn: null} implies the injectable should not be added
to any scope.