Skip to content

Commit

Permalink
refactor(ivy): in-line postProcessDirective to avoid repeated isCompo…
Browse files Browse the repository at this point in the history
…nentDef checks (#33322)

PR Close #33322
  • Loading branch information
pkozlowski-opensource authored and atscott committed Oct 31, 2019
1 parent 3ff712a commit 2c208f9
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions packages/core/src/render3/instructions/shared.ts
Expand Up @@ -1096,14 +1096,27 @@ function instantiateAllDirectives(tView: TView, lView: LView, tNode: TDirectiveH
if (!tView.firstTemplatePass) {
getOrCreateNodeInjectorForNode(tNode, lView);
}

for (let i = start; i < end; i++) {
const def = tView.data[i] as DirectiveDef<any>;
if (isComponentDef(def)) {
assertNodeOfPossibleTypes(tNode, TNodeType.Element);
addComponentLogic(lView, tNode as TElementNode, def);
const isComponent = isComponentDef(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);
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;
}
}
}

Expand Down Expand Up @@ -1169,23 +1182,6 @@ export function generateExpandoInstructionBlock(
])).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.
*/
Expand Down

0 comments on commit 2c208f9

Please sign in to comment.