refactor(ivy): remove TNode.dynamicContainerNode (#26407)

PR Close #26407
This commit is contained in:
Kara Erickson 2018-10-09 14:47:18 -07:00 committed by Miško Hevery
parent 989555352d
commit 70cd112872
5 changed files with 16 additions and 33 deletions

View File

@ -277,7 +277,6 @@ function appendI18nNode(
// Template containers also have a comment node for the `ViewContainerRef` that should be moved // Template containers also have a comment node for the `ViewContainerRef` that should be moved
if (tNode.type === TNodeType.Container && node.dynamicLContainerNode) { if (tNode.type === TNodeType.Container && node.dynamicLContainerNode) {
appendChild(node.dynamicLContainerNode.native, tNode, viewData); appendChild(node.dynamicLContainerNode.native, tNode, viewData);
return tNode.dynamicContainerNode !;
} }
return tNode; return tNode;
@ -376,7 +375,7 @@ export function i18nApply(startIndex: number, instructions: I18nInstruction[]):
// For template containers we also need to remove their `ViewContainerRef` from the DOM // For template containers we also need to remove their `ViewContainerRef` from the DOM
if (removedTNode.type === TNodeType.Container && removedNode.dynamicLContainerNode) { if (removedTNode.type === TNodeType.Container && removedNode.dynamicLContainerNode) {
removeChild(removedTNode, removedNode.dynamicLContainerNode.native || null, viewData); removeChild(removedTNode, removedNode.dynamicLContainerNode.native || null, viewData);
removedTNode.dynamicContainerNode !.detached = true; removedTNode.detached = true;
removedNode.dynamicLContainerNode.data[RENDER_PARENT] = null; removedNode.dynamicLContainerNode.data[RENDER_PARENT] = null;
} }
break; break;

View File

@ -496,8 +496,6 @@ export function createNodeAtIndex(
createTNode(type, adjustedIndex, name, attrs, tParent, null); createTNode(type, adjustedIndex, name, attrs, tParent, null);
if (!isParent && previousOrParentTNode) { if (!isParent && previousOrParentTNode) {
previousOrParentTNode.next = tNode; previousOrParentTNode.next = tNode;
if (previousOrParentTNode.dynamicContainerNode)
previousOrParentTNode.dynamicContainerNode.next = tNode;
} }
} }
@ -1518,7 +1516,6 @@ export function createTNode(
next: null, next: null,
child: null, child: null,
parent: parent, parent: parent,
dynamicContainerNode: null,
detached: null, detached: null,
stylingTemplate: null, stylingTemplate: null,
projection: null projection: null

View File

@ -325,11 +325,6 @@ export interface TNode {
*/ */
parent: TElementNode|TContainerNode|null; parent: TElementNode|TContainerNode|null;
/**
* A pointer to a TContainerNode created by directives requesting ViewContainerRef
*/
dynamicContainerNode: TNode|null;
/** /**
* If this node is part of an i18n block, it indicates whether this container is part of the DOM * If this node is part of an i18n block, it indicates whether this container is part of the DOM
* If this node is not part of an i18n block, this field is null. * If this node is not part of an i18n block, this field is null.

View File

@ -10,7 +10,7 @@ import {assertDefined} from './assert';
import {attachPatchData, readElementValue} from './context_discovery'; import {attachPatchData, readElementValue} from './context_discovery';
import {callHooks} from './hooks'; import {callHooks} from './hooks';
import {LContainer, RENDER_PARENT, VIEWS, unusedValueExportToPlacateAjd as unused1} from './interfaces/container'; import {LContainer, RENDER_PARENT, VIEWS, unusedValueExportToPlacateAjd as unused1} from './interfaces/container';
import {LContainerNode, LElementContainerNode, LElementNode, LTextNode, TContainerNode, TElementNode, TNode, TNodeFlags, TNodeType, TViewNode, unusedValueExportToPlacateAjd as unused2} from './interfaces/node'; import {LContainerNode, LElementContainerNode, LElementNode, LTextNode, TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeFlags, TNodeType, TViewNode, unusedValueExportToPlacateAjd as unused2} from './interfaces/node';
import {unusedValueExportToPlacateAjd as unused3} from './interfaces/projection'; import {unusedValueExportToPlacateAjd as unused3} from './interfaces/projection';
import {ProceduralRenderer3, RComment, RElement, RNode, RText, Renderer3, isProceduralRenderer, unusedValueExportToPlacateAjd as unused4} from './interfaces/renderer'; import {ProceduralRenderer3, RComment, RElement, RNode, RText, Renderer3, isProceduralRenderer, unusedValueExportToPlacateAjd as unused4} from './interfaces/renderer';
import {CLEANUP, CONTAINER_INDEX, FLAGS, HEADER_OFFSET, HOST_NODE, HookData, LViewData, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, TVIEW, unusedValueExportToPlacateAjd as unused5} from './interfaces/view'; import {CLEANUP, CONTAINER_INDEX, FLAGS, HEADER_OFFSET, HOST_NODE, HookData, LViewData, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, TVIEW, unusedValueExportToPlacateAjd as unused5} from './interfaces/view';
@ -393,9 +393,10 @@ export function detachView(lContainer: LContainer, removeIndex: number, detached
* @param removeIndex The index of the view to remove * @param removeIndex The index of the view to remove
*/ */
export function removeView( export function removeView(
lContainer: LContainer, tContainer: TContainerNode, removeIndex: number) { lContainer: LContainer, containerHost: TElementNode | TContainerNode | TElementContainerNode,
removeIndex: number) {
const view = lContainer[VIEWS][removeIndex]; const view = lContainer[VIEWS][removeIndex];
detachView(lContainer, removeIndex, !!tContainer.detached); detachView(lContainer, removeIndex, !!containerHost.detached);
destroyLView(view); destroyLView(view);
} }

View File

@ -105,13 +105,14 @@ export function createTemplateRef<T>(
} }
createEmbeddedView( createEmbeddedView(
context: T, container?: LContainer, tContainerNode?: TContainerNode, hostView?: LViewData, context: T, container?: LContainer,
hostTNode?: TElementNode|TContainerNode|TElementContainerNode, hostView?: LViewData,
index?: number): viewEngine_EmbeddedViewRef<T> { index?: number): viewEngine_EmbeddedViewRef<T> {
const lView = createEmbeddedViewAndNode( const lView = createEmbeddedViewAndNode(
this._tView, context, this._declarationParentView, this._renderer, this._queries, this._tView, context, this._declarationParentView, this._renderer, this._queries,
this._injectorIndex); this._injectorIndex);
if (container) { if (container) {
insertView(lView, container, hostView !, index !, tContainerNode !.parent !.index); insertView(lView, container, hostView !, index !, hostTNode !.index);
} }
renderEmbeddedTemplate(lView, this._tView, context, RenderFlags.Create); renderEmbeddedTemplate(lView, this._tView, context, RenderFlags.Create);
const viewRef = new ViewRef(lView, context, -1); const viewRef = new ViewRef(lView, context, -1);
@ -132,9 +133,8 @@ export function createTemplateRef<T>(
let R3ViewContainerRef: { let R3ViewContainerRef: {
new ( new (
lContainer: LContainer, tContainerNode: TContainerNode, lContainer: LContainer, hostTNode: TElementNode | TContainerNode | TElementContainerNode,
hostTNode: TElementNode | TContainerNode | TElementContainerNode, hostView: LViewData): hostView: LViewData): ViewEngine_ViewContainerRef
ViewEngine_ViewContainerRef
}; };
/** /**
@ -172,7 +172,7 @@ export function createContainerRef(
private _viewRefs: viewEngine_ViewRef[] = []; private _viewRefs: viewEngine_ViewRef[] = [];
constructor( constructor(
private _lContainer: LContainer, private _tContainerNode: TContainerNode, private _lContainer: LContainer,
private _hostTNode: TElementNode|TContainerNode|TElementContainerNode, private _hostTNode: TElementNode|TContainerNode|TElementContainerNode,
private _hostView: LViewData) { private _hostView: LViewData) {
super(); super();
@ -210,7 +210,7 @@ export function createContainerRef(
const adjustedIdx = this._adjustIndex(index); const adjustedIdx = this._adjustIndex(index);
const viewRef = (templateRef as any) const viewRef = (templateRef as any)
.createEmbeddedView( .createEmbeddedView(
context || <any>{}, this._lContainer, this._tContainerNode, context || <any>{}, this._lContainer, this._hostTNode,
this._hostView, adjustedIdx); this._hostView, adjustedIdx);
(viewRef as ViewRef<any>).attachToViewContainerRef(this); (viewRef as ViewRef<any>).attachToViewContainerRef(this);
this._viewRefs.splice(adjustedIdx, 0, viewRef); this._viewRefs.splice(adjustedIdx, 0, viewRef);
@ -239,9 +239,7 @@ export function createContainerRef(
const lView = (viewRef as ViewRef<any>)._view !; const lView = (viewRef as ViewRef<any>)._view !;
const adjustedIdx = this._adjustIndex(index); const adjustedIdx = this._adjustIndex(index);
insertView( insertView(lView, this._lContainer, this._hostView, adjustedIdx, this._hostTNode.index);
lView, this._lContainer, this._hostView, adjustedIdx,
this._tContainerNode.parent !.index);
const container = this._getHostNode().dynamicLContainerNode !; const container = this._getHostNode().dynamicLContainerNode !;
const beforeNode = getBeforeNodeForView(adjustedIdx, this._lContainer[VIEWS], container); const beforeNode = getBeforeNodeForView(adjustedIdx, this._lContainer[VIEWS], container);
@ -264,13 +262,13 @@ export function createContainerRef(
remove(index?: number): void { remove(index?: number): void {
const adjustedIdx = this._adjustIndex(index, -1); const adjustedIdx = this._adjustIndex(index, -1);
removeView(this._lContainer, this._tContainerNode as TContainerNode, adjustedIdx); removeView(this._lContainer, this._hostTNode, adjustedIdx);
this._viewRefs.splice(adjustedIdx, 1); this._viewRefs.splice(adjustedIdx, 1);
} }
detach(index?: number): viewEngine_ViewRef|null { detach(index?: number): viewEngine_ViewRef|null {
const adjustedIdx = this._adjustIndex(index, -1); const adjustedIdx = this._adjustIndex(index, -1);
detachView(this._lContainer, adjustedIdx, !!this._tContainerNode.detached); detachView(this._lContainer, adjustedIdx, !!this._hostTNode.detached);
return this._viewRefs.splice(adjustedIdx, 1)[0] || null; return this._viewRefs.splice(adjustedIdx, 1)[0] || null;
} }
@ -302,17 +300,10 @@ export function createContainerRef(
lContainer[RENDER_PARENT] = getRenderParent(hostTNode, hostView); lContainer[RENDER_PARENT] = getRenderParent(hostTNode, hostView);
appendChild(comment, hostTNode, hostView); appendChild(comment, hostTNode, hostView);
if (!hostTNode.dynamicContainerNode) {
hostTNode.dynamicContainerNode =
createTNode(TNodeType.Container, -1, null, null, hostTNode, null);
}
hostLNode.dynamicLContainerNode = lContainerNode; hostLNode.dynamicLContainerNode = lContainerNode;
addToViewTree(hostView, hostTNode.index as number, lContainer); addToViewTree(hostView, hostTNode.index as number, lContainer);
return new R3ViewContainerRef( return new R3ViewContainerRef(lContainer, hostTNode, hostView);
lContainer, hostTNode.dynamicContainerNode as TContainerNode, hostTNode, hostView);
} }