refactor(ivy): in-line postProcessDirective to avoid repeated isComponentDef checks (#33322)
PR Close #33322
This commit is contained in:
parent
3ff712a0f5
commit
2c208f98a9
@ -1096,14 +1096,27 @@ function instantiateAllDirectives(tView: TView, lView: LView, tNode: TDirectiveH
|
|||||||
if (!tView.firstTemplatePass) {
|
if (!tView.firstTemplatePass) {
|
||||||
getOrCreateNodeInjectorForNode(tNode, lView);
|
getOrCreateNodeInjectorForNode(tNode, lView);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = start; i < end; i++) {
|
for (let i = start; i < end; i++) {
|
||||||
const def = tView.data[i] as DirectiveDef<any>;
|
const def = tView.data[i] as DirectiveDef<any>;
|
||||||
if (isComponentDef(def)) {
|
const isComponent = isComponentDef(def);
|
||||||
assertNodeOfPossibleTypes(tNode, TNodeType.Element);
|
|
||||||
addComponentLogic(lView, tNode as TElementNode, def);
|
if (isComponent) {
|
||||||
|
ngDevMode && assertNodeOfPossibleTypes(tNode, TNodeType.Element);
|
||||||
|
addComponentLogic(lView, tNode as TElementNode, def as ComponentDef<any>);
|
||||||
}
|
}
|
||||||
|
|
||||||
const directive = getNodeInjectable(tView.data, lView, i, tNode);
|
const directive = getNodeInjectable(tView.data, lView, i, tNode);
|
||||||
postProcessDirective(lView, tNode, directive, def, i - start);
|
|
||||||
|
postProcessBaseDirective(lView, tNode, directive);
|
||||||
|
if (tNode.initialInputs !== null) {
|
||||||
|
setInputsFromAttrs(lView, i - start, directive, def, tNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isComponent) {
|
||||||
|
const componentView = getComponentLViewByIndex(tNode.index, lView);
|
||||||
|
componentView[CONTEXT] = directive;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1169,23 +1182,6 @@ export function generateExpandoInstructionBlock(
|
|||||||
])).push(elementIndex, providerCount, directiveCount);
|
])).push(elementIndex, providerCount, directiveCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Process a directive on the current node after its creation.
|
|
||||||
*/
|
|
||||||
function postProcessDirective<T>(
|
|
||||||
lView: LView, hostTNode: TNode, directive: T, def: DirectiveDef<T>,
|
|
||||||
directiveDefIdx: number): void {
|
|
||||||
postProcessBaseDirective(lView, hostTNode, directive);
|
|
||||||
if (hostTNode.initialInputs !== null) {
|
|
||||||
setInputsFromAttrs(lView, directiveDefIdx, directive, def, hostTNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isComponentDef(def)) {
|
|
||||||
const componentView = getComponentLViewByIndex(hostTNode.index, lView);
|
|
||||||
componentView[CONTEXT] = directive;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lighter version of postProcessDirective() that is used for the root component.
|
* A lighter version of postProcessDirective() that is used for the root component.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user