refactor(ivy): remove TNode.dynamicContainerNode (#26407)
PR Close #26407
This commit is contained in:
parent
989555352d
commit
70cd112872
|
@ -277,7 +277,6 @@ function appendI18nNode(
|
|||
// Template containers also have a comment node for the `ViewContainerRef` that should be moved
|
||||
if (tNode.type === TNodeType.Container && node.dynamicLContainerNode) {
|
||||
appendChild(node.dynamicLContainerNode.native, tNode, viewData);
|
||||
return tNode.dynamicContainerNode !;
|
||||
}
|
||||
|
||||
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
|
||||
if (removedTNode.type === TNodeType.Container && removedNode.dynamicLContainerNode) {
|
||||
removeChild(removedTNode, removedNode.dynamicLContainerNode.native || null, viewData);
|
||||
removedTNode.dynamicContainerNode !.detached = true;
|
||||
removedTNode.detached = true;
|
||||
removedNode.dynamicLContainerNode.data[RENDER_PARENT] = null;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -496,8 +496,6 @@ export function createNodeAtIndex(
|
|||
createTNode(type, adjustedIndex, name, attrs, tParent, null);
|
||||
if (!isParent && previousOrParentTNode) {
|
||||
previousOrParentTNode.next = tNode;
|
||||
if (previousOrParentTNode.dynamicContainerNode)
|
||||
previousOrParentTNode.dynamicContainerNode.next = tNode;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1518,7 +1516,6 @@ export function createTNode(
|
|||
next: null,
|
||||
child: null,
|
||||
parent: parent,
|
||||
dynamicContainerNode: null,
|
||||
detached: null,
|
||||
stylingTemplate: null,
|
||||
projection: null
|
||||
|
|
|
@ -325,11 +325,6 @@ export interface TNode {
|
|||
*/
|
||||
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 not part of an i18n block, this field is null.
|
||||
|
|
|
@ -10,7 +10,7 @@ import {assertDefined} from './assert';
|
|||
import {attachPatchData, readElementValue} from './context_discovery';
|
||||
import {callHooks} from './hooks';
|
||||
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 {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';
|
||||
|
@ -393,9 +393,10 @@ export function detachView(lContainer: LContainer, removeIndex: number, detached
|
|||
* @param removeIndex The index of the view to remove
|
||||
*/
|
||||
export function removeView(
|
||||
lContainer: LContainer, tContainer: TContainerNode, removeIndex: number) {
|
||||
lContainer: LContainer, containerHost: TElementNode | TContainerNode | TElementContainerNode,
|
||||
removeIndex: number) {
|
||||
const view = lContainer[VIEWS][removeIndex];
|
||||
detachView(lContainer, removeIndex, !!tContainer.detached);
|
||||
detachView(lContainer, removeIndex, !!containerHost.detached);
|
||||
destroyLView(view);
|
||||
}
|
||||
|
||||
|
|
|
@ -105,13 +105,14 @@ export function createTemplateRef<T>(
|
|||
}
|
||||
|
||||
createEmbeddedView(
|
||||
context: T, container?: LContainer, tContainerNode?: TContainerNode, hostView?: LViewData,
|
||||
context: T, container?: LContainer,
|
||||
hostTNode?: TElementNode|TContainerNode|TElementContainerNode, hostView?: LViewData,
|
||||
index?: number): viewEngine_EmbeddedViewRef<T> {
|
||||
const lView = createEmbeddedViewAndNode(
|
||||
this._tView, context, this._declarationParentView, this._renderer, this._queries,
|
||||
this._injectorIndex);
|
||||
if (container) {
|
||||
insertView(lView, container, hostView !, index !, tContainerNode !.parent !.index);
|
||||
insertView(lView, container, hostView !, index !, hostTNode !.index);
|
||||
}
|
||||
renderEmbeddedTemplate(lView, this._tView, context, RenderFlags.Create);
|
||||
const viewRef = new ViewRef(lView, context, -1);
|
||||
|
@ -132,9 +133,8 @@ export function createTemplateRef<T>(
|
|||
|
||||
let R3ViewContainerRef: {
|
||||
new (
|
||||
lContainer: LContainer, tContainerNode: TContainerNode,
|
||||
hostTNode: TElementNode | TContainerNode | TElementContainerNode, hostView: LViewData):
|
||||
ViewEngine_ViewContainerRef
|
||||
lContainer: LContainer, hostTNode: TElementNode | TContainerNode | TElementContainerNode,
|
||||
hostView: LViewData): ViewEngine_ViewContainerRef
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -172,7 +172,7 @@ export function createContainerRef(
|
|||
private _viewRefs: viewEngine_ViewRef[] = [];
|
||||
|
||||
constructor(
|
||||
private _lContainer: LContainer, private _tContainerNode: TContainerNode,
|
||||
private _lContainer: LContainer,
|
||||
private _hostTNode: TElementNode|TContainerNode|TElementContainerNode,
|
||||
private _hostView: LViewData) {
|
||||
super();
|
||||
|
@ -210,7 +210,7 @@ export function createContainerRef(
|
|||
const adjustedIdx = this._adjustIndex(index);
|
||||
const viewRef = (templateRef as any)
|
||||
.createEmbeddedView(
|
||||
context || <any>{}, this._lContainer, this._tContainerNode,
|
||||
context || <any>{}, this._lContainer, this._hostTNode,
|
||||
this._hostView, adjustedIdx);
|
||||
(viewRef as ViewRef<any>).attachToViewContainerRef(this);
|
||||
this._viewRefs.splice(adjustedIdx, 0, viewRef);
|
||||
|
@ -239,9 +239,7 @@ export function createContainerRef(
|
|||
const lView = (viewRef as ViewRef<any>)._view !;
|
||||
const adjustedIdx = this._adjustIndex(index);
|
||||
|
||||
insertView(
|
||||
lView, this._lContainer, this._hostView, adjustedIdx,
|
||||
this._tContainerNode.parent !.index);
|
||||
insertView(lView, this._lContainer, this._hostView, adjustedIdx, this._hostTNode.index);
|
||||
|
||||
const container = this._getHostNode().dynamicLContainerNode !;
|
||||
const beforeNode = getBeforeNodeForView(adjustedIdx, this._lContainer[VIEWS], container);
|
||||
|
@ -264,13 +262,13 @@ export function createContainerRef(
|
|||
|
||||
remove(index?: number): void {
|
||||
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);
|
||||
}
|
||||
|
||||
detach(index?: number): viewEngine_ViewRef|null {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -302,17 +300,10 @@ export function createContainerRef(
|
|||
lContainer[RENDER_PARENT] = getRenderParent(hostTNode, hostView);
|
||||
|
||||
appendChild(comment, hostTNode, hostView);
|
||||
|
||||
if (!hostTNode.dynamicContainerNode) {
|
||||
hostTNode.dynamicContainerNode =
|
||||
createTNode(TNodeType.Container, -1, null, null, hostTNode, null);
|
||||
}
|
||||
|
||||
hostLNode.dynamicLContainerNode = lContainerNode;
|
||||
addToViewTree(hostView, hostTNode.index as number, lContainer);
|
||||
|
||||
return new R3ViewContainerRef(
|
||||
lContainer, hostTNode.dynamicContainerNode as TContainerNode, hostTNode, hostView);
|
||||
return new R3ViewContainerRef(lContainer, hostTNode, hostView);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue