refactor(ivy): remove code duplication from applyXYZ functions (#31182)

PR Close #31182
This commit is contained in:
Pawel Kozlowski 2019-06-24 17:21:02 +02:00 committed by Kara Erickson
parent 29a9909232
commit 103064a3d0
1 changed files with 22 additions and 44 deletions

View File

@ -764,18 +764,7 @@ function applyView(
ngDevMode && assertNodeType(tView.node !, TNodeType.View); ngDevMode && assertNodeType(tView.node !, TNodeType.View);
let viewRootTNode: TNode|null = tView.node !.child; let viewRootTNode: TNode|null = tView.node !.child;
while (viewRootTNode !== null) { while (viewRootTNode !== null) {
const viewRootTNodeType = viewRootTNode.type; executeActionOnTNode(renderer, action, lView, viewRootTNode, renderParent, beforeNode);
if (viewRootTNodeType === TNodeType.ElementContainer) {
applyElementContainer(
renderer, action, lView, viewRootTNode as TElementContainerNode, renderParent,
beforeNode);
} else if (viewRootTNodeType === TNodeType.Projection) {
applyProjection(
renderer, action, lView, viewRootTNode as TProjectionNode, renderParent, beforeNode);
} else {
ngDevMode && assertNodeOfPossibleTypes(viewRootTNode, TNodeType.Element, TNodeType.Container);
executeNodeAction(action, renderer, renderParent, lView[viewRootTNode.index], beforeNode);
}
viewRootTNode = viewRootTNode.next; viewRootTNode = viewRootTNode.next;
} }
} }
@ -810,20 +799,8 @@ function applyProjection(
let projectionTNode: TNode|null = nodeToProject; let projectionTNode: TNode|null = nodeToProject;
const projectedComponentLView = componentLView[PARENT] as LView; const projectedComponentLView = componentLView[PARENT] as LView;
while (projectionTNode !== null) { while (projectionTNode !== null) {
if (projectionTNode.type === TNodeType.ElementContainer) { executeActionOnTNode(
applyElementContainer( renderer, action, projectedComponentLView, projectionTNode, renderParent, beforeNode);
renderer, action, projectedComponentLView, projectionTNode as TElementContainerNode,
renderParent, beforeNode);
} else if (projectionTNode.type === TNodeType.Projection) {
applyProjection(
renderer, action, projectedComponentLView, projectionTNode as TProjectionNode,
renderParent, beforeNode);
} else {
const rNode = projectedComponentLView[projectionTNode.index];
ngDevMode &&
assertNodeOfPossibleTypes(projectionTNode, TNodeType.Element, TNodeType.Container);
executeNodeAction(action, renderer, renderParent, rNode, beforeNode);
}
projectionTNode = projectionTNode.projectionNext; projectionTNode = projectionTNode.projectionNext;
} }
} }
@ -882,23 +859,24 @@ function applyElementContainer(
beforeNode: RNode | null | undefined) { beforeNode: RNode | null | undefined) {
const node = lView[tElementContainerNode.index]; const node = lView[tElementContainerNode.index];
executeNodeAction(action, renderer, renderParent, node, beforeNode); executeNodeAction(action, renderer, renderParent, node, beforeNode);
let elementContainerRootTNode: TNode|null = tElementContainerNode.child; let childTNode: TNode|null = tElementContainerNode.child;
while (elementContainerRootTNode) { while (childTNode) {
const elementContainerRootTNodeType = elementContainerRootTNode.type; executeActionOnTNode(renderer, action, lView, childTNode, renderParent, beforeNode);
if (elementContainerRootTNodeType === TNodeType.ElementContainer) { childTNode = childTNode.next;
applyElementContainer( }
renderer, action, lView, elementContainerRootTNode as TElementContainerNode, renderParent, }
beforeNode);
} else if (elementContainerRootTNodeType === TNodeType.Projection) { function executeActionOnTNode(
applyProjection( renderer: Renderer3, action: WalkTNodeTreeAction, lView: LView, tNode: TNode,
renderer, action, lView, elementContainerRootTNode as TProjectionNode, renderParent, renderParent: RElement | null, beforeNode: RNode | null | undefined): void {
beforeNode); const elementContainerRootTNodeType = tNode.type;
} else { if (elementContainerRootTNodeType === TNodeType.ElementContainer) {
ngDevMode && assertNodeOfPossibleTypes( applyElementContainer(
elementContainerRootTNode, TNodeType.Element, TNodeType.Container); renderer, action, lView, tNode as TElementContainerNode, renderParent, beforeNode);
executeNodeAction( } else if (elementContainerRootTNodeType === TNodeType.Projection) {
action, renderer, renderParent, lView[elementContainerRootTNode.index], beforeNode); applyProjection(renderer, action, lView, tNode as TProjectionNode, renderParent, beforeNode);
} } else {
elementContainerRootTNode = elementContainerRootTNode.next; ngDevMode && assertNodeOfPossibleTypes(tNode, TNodeType.Element, TNodeType.Container);
executeNodeAction(action, renderer, renderParent, lView[tNode.index], beforeNode);
} }
} }