Conversation
a0ddeba to
74b9350
Compare
| */ | ||
| jit?: true; | ||
|
|
||
| standalone?: boolean; |
| */ | ||
| preserveWhitespaces?: boolean; | ||
|
|
||
| standalone?: boolean; |
| standalone?: boolean; | ||
|
|
||
| // TODO: better type here! | ||
| imports?: (Type<any>|any[])[]; |
| */ | ||
| pure?: boolean; | ||
|
|
||
| standalone?: boolean; |
| const dep = resolveForwardRef(rawDep); | ||
| if (!dep) { | ||
| // TODO: real error | ||
| throw new Error(`ForwardRef issue?`); |
There was a problem hiding this comment.
needs proper error
| if (anyDef) { | ||
| if (!anyDef.standalone) { | ||
| // TODO: real error | ||
| throw new Error(`What are you doing? You imported a non-standalone thing!`); |
There was a problem hiding this comment.
needs proper error
| viewQueries: extractQueriesMetadata(type, propMetadata, isViewQuery), | ||
| // TODO(alxhub): pass through the standalone flag from the directive metadata once standalone | ||
| // functionality is fully rolled out. | ||
| isStandalone: false, |
There was a problem hiding this comment.
I guess the above comment is no longer relevant?
| } | ||
|
|
||
| // TODO: change the error message to be more user-facing and take standalone into account | ||
| throw new Error(`${type.name} does not have a module def (ɵmod property)`); |
There was a problem hiding this comment.
needs better error?
3eff87a to
1af65d9
Compare
| // TODO: real error | ||
| throw new Error(`ForwardRef issue?`); | ||
| } | ||
| const ngModuleDef: NgModuleDef<any>|null = getNgModuleDef(dep); |
There was a problem hiding this comment.
| const ngModuleDef: NgModuleDef<any>|null = getNgModuleDef(dep); | |
| const ngModuleDef = getNgModuleDef<Type<unknown>>(dep); |
Should this have a more restrictive type?
| if (ngModuleDef) { | ||
| dependencies.push({ | ||
| kind: R3TemplateDependencyKind.NgModule, | ||
| type: dep as any, |
There was a problem hiding this comment.
Is the as any needed here?
| importingModule?: NgModuleType): void { | ||
| if (verifiedNgModule.get(moduleType)) return; | ||
|
|
||
| // skip verifications of standalone components, direcrtives and pipes |
There was a problem hiding this comment.
nit: this comment is "what" but not why. It's mostly obvious that if (isStandalone(moduleType)) return; skips the verification. This comment should be updated to explain why or deleted. Also "direcrtives" is misspelled.
| flatten(imports).map(unwrapModuleWithProvidersImports).forEach(mod => { | ||
| verifySemanticsOfNgModuleImport(mod, moduleType); | ||
| verifySemanticsOfNgModuleDef(mod, false, moduleType); | ||
| flatten(imports).map(unwrapModuleWithProvidersImports).forEach(modOrStandaloneCmpt => { |
There was a problem hiding this comment.
uber(!!) nit: We generally use Cmp for the shorthand of "component" if we're doing that. The "t" almost looks like a typo to me.
| const ngModuleDef = getNgModuleDef(type); | ||
|
|
||
| // a standalone component, directive or pipe | ||
| if (ngModuleDef === null) { | ||
| return [type]; | ||
| } |
There was a problem hiding this comment.
| const ngModuleDef = getNgModuleDef(type); | |
| // a standalone component, directive or pipe | |
| if (ngModuleDef === null) { | |
| return [type]; | |
| } | |
| if (isStandalone(type)) { | |
| return [type]; | |
| } | |
| const ngModuleDef = getNgModuleDef(type, true); |
nit: Personally I would think this would be easier to read and doesn't need a comment. But I can imagine it's slightly less optimal because there are a couple more lookups involved by calling isStandalone
| * TODO(pk): documentation | ||
| * A feature that acts as a setup code for the {@see StandaloneService}. | ||
| * | ||
| * The most important responsaibility of this feature is to expose the "getStandaloneInjector" |
There was a problem hiding this comment.
nit: s/responsaibility/responsibility
AndrewKushnir
left a comment
There was a problem hiding this comment.
LGTM, just left a few comments. None of them are blockers and we can look into them in a followup PR.
There was a problem hiding this comment.
nit: can we add a TODO to add a comment here in a followup PR?
There was a problem hiding this comment.
nit: it'd be great to extract componentDefinition.standalone === true into a separate const and reuse in 2 places above (for code size optimization):
const standalone = componentDefinition.standalone === true;
(let's leave a TODO and I can cleanup in a followup PR)
| // skip verifications of standalone components, direcrtives and pipes | ||
| if (isStandalone(moduleType)) return; |
There was a problem hiding this comment.
Do we have a verification somewhere else or it should be implemented as a followup?
There was a problem hiding this comment.
I'm not sure if "skip verification" here is a TODO for later - I think this means "skip NgModule verification"
There was a problem hiding this comment.
Yeah, I was wondering if we do similar verification for imported standalone types somewhere else (thus we don't need it).
| const ngModuleDef = getNgModuleDef(type, true); | ||
| const ngModuleDef = getNgModuleDef(type); | ||
|
|
||
| // a standalone component, directive or pipe |
There was a problem hiding this comment.
nit: I think adding an assert here (in a followup PR) to check that a type is actually standalone would be great.
atscott
left a comment
There was a problem hiding this comment.
reviewed-for: size-tracking, public-api
|
Caretaker: the functions here have already been reviewed for public-api (in a previous commit, they just didn't make it into the golden, for reasons). Consider it approved! |
AndrewKushnir
left a comment
There was a problem hiding this comment.
Reviewed-for: size-tracking, public-api
This commit extracts the `importProvidersFrom` function and associated machinery into a separate file, as opposed to being colocated with `R3Injector`. Separating these functions will mitigate potential future circular dependencies as `importProvidersFrom` starts being used in different parts of the codebase.
This commit exposes the `standalone` flag on `@Directive`, `@Component`, and `@Pipe`, effectively making standalone components a part of Angular's public API. As part of this operation, it also implements JIT compilation for standalone types. Standalone types are Angular-decorated types which act as their own "declarations", where they would otherwise be declared in an NgModule. Marking an Angular type as standalone means that it can be used directly in other standalone components and in NgModules, without needing an associated NgModule to depend on it. In the case of a standalone component, template dependencies which would otherwise be specified by an NgModule are instead specified directly on the component itself, via the `imports` field. Other standalone types can be imported, as well as NgModules.
This commit refactors `importProvidersFrom` to support pulling providers from the dependencies of a standalone component, in addition to NgModules. Tests will be added in a future commit when standalone components can be created without calling private APIs.
This commit implements the `StandaloneFeature` which provides for the creation of standalone injectors, for those components which need them. The feature-based implementation ensures the machinery for standalone injectors is properly tree-shakable.
This commit reorganizes the tests around the EnvironmentInjector and its use for standalone injectors, and adds a number of new test cases.
This commit adds some internal documentation.
|
This PR was merged into the repository by commit 9e4c4bc. |
…45687) This commit exposes the `standalone` flag on `@Directive`, `@Component`, and `@Pipe`, effectively making standalone components a part of Angular's public API. As part of this operation, it also implements JIT compilation for standalone types. Standalone types are Angular-decorated types which act as their own "declarations", where they would otherwise be declared in an NgModule. Marking an Angular type as standalone means that it can be used directly in other standalone components and in NgModules, without needing an associated NgModule to depend on it. In the case of a standalone component, template dependencies which would otherwise be specified by an NgModule are instead specified directly on the component itself, via the `imports` field. Other standalone types can be imported, as well as NgModules. PR Close #45687
This commit implements the `StandaloneFeature` which provides for the creation of standalone injectors, for those components which need them. The feature-based implementation ensures the machinery for standalone injectors is properly tree-shakable. PR Close #45687
This commit reorganizes the tests around the EnvironmentInjector and its use for standalone injectors, and adds a number of new test cases. PR Close #45687
This commit adds some internal documentation. PR Close #45687
This commit updates the standalone-related logic to address the feedback from previous code reviews (specifically: angular#45687 (comment)).
…45949) This commit updates the standalone-related logic to address the feedback from previous code reviews (specifically: #45687 (comment)). PR Close #45949
…45949) This commit updates the standalone-related logic to address the feedback from previous code reviews (specifically: #45687 (comment)). PR Close #45949
|
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. |
This PR is based on #45672, and adds JIT compilation as well as the actual public API for standalone components 🎉
There's still work to be done after this: