mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(core): cache ComponentRef inputs and outputs (#60156)
The set of inputs and outputs of a component is static, but the getter for the `inputs` and `outputs` property was re-computing them every time which the user might not expect. These changes add a couple of lines to cache them instead. PR Close #60156
This commit is contained in:
committed by
Miles Malerba
parent
7ab0a8d1e7
commit
af02914852
@@ -186,6 +186,15 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
|
||||
override componentType: Type<any>;
|
||||
override ngContentSelectors: string[];
|
||||
isBoundToModule: boolean;
|
||||
private cachedInputs:
|
||||
| {
|
||||
propName: string;
|
||||
templateName: string;
|
||||
isSignal: boolean;
|
||||
transform?: (value: any) => any;
|
||||
}[]
|
||||
| null = null;
|
||||
private cachedOutputs: {propName: string; templateName: string}[] | null = null;
|
||||
|
||||
override get inputs(): {
|
||||
propName: string;
|
||||
@@ -193,11 +202,13 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
|
||||
isSignal: boolean;
|
||||
transform?: (value: any) => any;
|
||||
}[] {
|
||||
return toInputRefArray(this.componentDef.inputs);
|
||||
this.cachedInputs ??= toInputRefArray(this.componentDef.inputs);
|
||||
return this.cachedInputs;
|
||||
}
|
||||
|
||||
override get outputs(): {propName: string; templateName: string}[] {
|
||||
return toOutputRefArray(this.componentDef.outputs);
|
||||
this.cachedOutputs ??= toOutputRefArray(this.componentDef.outputs);
|
||||
return this.cachedOutputs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user