refactor(ivy): cleanup implementation of container related instructions (#31142)

PR Close #31142
This commit is contained in:
Pawel Kozlowski 2019-06-19 18:09:58 +02:00 committed by Matias Niemelä
parent 0110de2662
commit 1ac07757dd
1 changed files with 10 additions and 10 deletions

View File

@ -33,8 +33,9 @@ import {addToViewTree, createDirectivesAndLocals, createLContainer, createTView,
* @codeGenApi * @codeGenApi
*/ */
export function ɵɵcontainer(index: number): void { export function ɵɵcontainer(index: number): void {
const tNode = containerInternal(index, null, null);
const lView = getLView(); const lView = getLView();
const tNode = containerInternal(lView, index, null, null);
if (lView[TVIEW].firstTemplatePass) { if (lView[TVIEW].firstTemplatePass) {
tNode.tViews = []; tNode.tViews = [];
} }
@ -69,7 +70,7 @@ export function ɵɵtemplate(
const tView = lView[TVIEW]; const tView = lView[TVIEW];
// TODO: consider a separate node type for templates // TODO: consider a separate node type for templates
const tContainerNode = containerInternal(index, tagName || null, attrs || null); const tContainerNode = containerInternal(lView, index, tagName || null, attrs || null);
if (tView.firstTemplatePass) { if (tView.firstTemplatePass) {
tContainerNode.tViews = createTView( tContainerNode.tViews = createTView(
-1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null, null); -1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null, null);
@ -159,21 +160,20 @@ function addTContainerToQueries(lView: LView, tContainerNode: TContainerNode): v
} }
function containerInternal( function containerInternal(
index: number, tagName: string | null, attrs: TAttributes | null): TContainerNode { lView: LView, nodeIndex: number, tagName: string | null,
const lView = getLView(); attrs: TAttributes | null): TContainerNode {
ngDevMode && assertEqual( ngDevMode && assertEqual(
lView[BINDING_INDEX], lView[TVIEW].bindingStartIndex, lView[BINDING_INDEX], lView[TVIEW].bindingStartIndex,
'container nodes should be created before any bindings'); 'container nodes should be created before any bindings');
const adjustedIndex = index + HEADER_OFFSET; const adjustedIndex = nodeIndex + HEADER_OFFSET;
ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET); ngDevMode && assertDataInRange(lView, nodeIndex + HEADER_OFFSET);
ngDevMode && ngDevMode.rendererCreateComment++; ngDevMode && ngDevMode.rendererCreateComment++;
const comment = lView[index + HEADER_OFFSET] = const comment = lView[adjustedIndex] =
lView[RENDERER].createComment(ngDevMode ? 'container' : ''); lView[RENDERER].createComment(ngDevMode ? 'container' : '');
const tNode = const tNode =
getOrCreateTNode(lView[TVIEW], lView[T_HOST], index, TNodeType.Container, tagName, attrs); getOrCreateTNode(lView[TVIEW], lView[T_HOST], nodeIndex, TNodeType.Container, tagName, attrs);
const lContainer = lView[adjustedIndex] = const lContainer = lView[adjustedIndex] = createLContainer(comment, lView, comment, tNode);
createLContainer(lView[adjustedIndex], lView, comment, tNode);
appendChild(comment, tNode, lView); appendChild(comment, tNode, lView);