refactor(ivy): remove unneeded detach property (#28595)

PR Close #28595
This commit is contained in:
Olivier Combe 2019-02-07 17:03:29 +01:00 committed by Miško Hevery
parent 9d109929be
commit 94f042beba
5 changed files with 12 additions and 30 deletions

View File

@ -854,9 +854,6 @@ function removeNode(index: number, viewData: LView) {
nativeRemoveNode(viewData[RENDERER], removedPhRNode); nativeRemoveNode(viewData[RENDERER], removedPhRNode);
} }
removedPhTNode.detached = true;
ngDevMode && ngDevMode.rendererRemoveNode++;
const slotValue = load(index) as RElement | RComment | LContainer | StylingContext; const slotValue = load(index) as RElement | RComment | LContainer | StylingContext;
if (isLContainer(slotValue)) { if (isLContainer(slotValue)) {
const lContainer = slotValue as LContainer; const lContainer = slotValue as LContainer;
@ -864,6 +861,8 @@ function removeNode(index: number, viewData: LView) {
nativeRemoveNode(viewData[RENDERER], lContainer[NATIVE]); nativeRemoveNode(viewData[RENDERER], lContainer[NATIVE]);
} }
} }
ngDevMode && ngDevMode.rendererRemoveNode++;
} }
/** /**

View File

@ -1287,7 +1287,6 @@ export function createTNode(
next: null, next: null,
child: null, child: null,
parent: tParent, parent: tParent,
detached: null,
stylingTemplate: null, stylingTemplate: null,
projection: null projection: null
}; };
@ -2240,7 +2239,7 @@ export function containerRefreshEnd(): void {
// remove extra views at the end of the container // remove extra views at the end of the container
while (nextIndex < lContainer[VIEWS].length) { while (nextIndex < lContainer[VIEWS].length) {
removeView(lContainer, previousOrParentTNode as TContainerNode, nextIndex); removeView(lContainer, nextIndex);
} }
} }
@ -2271,14 +2270,11 @@ function refreshDynamicEmbeddedViews(lView: LView) {
* Removes views that need to be deleted in the process. * Removes views that need to be deleted in the process.
* *
* @param lContainer to search for views * @param lContainer to search for views
* @param tContainerNode to search for views
* @param startIdx starting index in the views array to search from * @param startIdx starting index in the views array to search from
* @param viewBlockId exact view block id to look for * @param viewBlockId exact view block id to look for
* @returns index of a found view or -1 if not found * @returns index of a found view or -1 if not found
*/ */
function scanForView( function scanForView(lContainer: LContainer, startIdx: number, viewBlockId: number): LView|null {
lContainer: LContainer, tContainerNode: TContainerNode, startIdx: number,
viewBlockId: number): LView|null {
const views = lContainer[VIEWS]; const views = lContainer[VIEWS];
for (let i = startIdx; i < views.length; i++) { for (let i = startIdx; i < views.length; i++) {
const viewAtPositionId = views[i][TVIEW].id; const viewAtPositionId = views[i][TVIEW].id;
@ -2286,7 +2282,7 @@ function scanForView(
return views[i]; return views[i];
} else if (viewAtPositionId < viewBlockId) { } else if (viewAtPositionId < viewBlockId) {
// found a view that should not be at this position - remove // found a view that should not be at this position - remove
removeView(lContainer, tContainerNode, i); removeView(lContainer, i);
} else { } else {
// found a view with id greater than the one we are searching for // found a view with id greater than the one we are searching for
// which means that required view doesn't exist and can't be found at // which means that required view doesn't exist and can't be found at
@ -2313,8 +2309,7 @@ export function embeddedViewStart(viewBlockId: number, consts: number, vars: num
const lContainer = lView[containerTNode.index] as LContainer; const lContainer = lView[containerTNode.index] as LContainer;
ngDevMode && assertNodeType(containerTNode, TNodeType.Container); ngDevMode && assertNodeType(containerTNode, TNodeType.Container);
let viewToRender = scanForView( let viewToRender = scanForView(lContainer, lContainer[ACTIVE_INDEX] !, viewBlockId);
lContainer, containerTNode as TContainerNode, lContainer[ACTIVE_INDEX] !, viewBlockId);
if (viewToRender) { if (viewToRender) {
setIsParent(true); setIsParent(true);

View File

@ -304,12 +304,6 @@ export interface TNode {
*/ */
parent: TElementNode|TContainerNode|null; parent: TElementNode|TContainerNode|null;
/**
* If this node is part of an i18n block, it indicates whether this node is part of the DOM.
* If this node is not part of an i18n block, this field is null.
*/
detached: boolean|null;
stylingTemplate: StylingContext|null; stylingTemplate: StylingContext|null;
/** /**
* List of projected TNodes for a given component host element OR index into the said nodes. * List of projected TNodes for a given component host element OR index into the said nodes.

View File

@ -340,19 +340,16 @@ export function insertView(
* *
* @param lContainer The container from which to detach a view * @param lContainer The container from which to detach a view
* @param removeIndex The index of the view to detach * @param removeIndex The index of the view to detach
* @param detached Whether or not this view is already detached.
* @returns Detached LView instance. * @returns Detached LView instance.
*/ */
export function detachView(lContainer: LContainer, removeIndex: number, detached: boolean): LView { export function detachView(lContainer: LContainer, removeIndex: number): LView {
const views = lContainer[VIEWS]; const views = lContainer[VIEWS];
const viewToDetach = views[removeIndex]; const viewToDetach = views[removeIndex];
if (removeIndex > 0) { if (removeIndex > 0) {
views[removeIndex - 1][NEXT] = viewToDetach[NEXT] as LView; views[removeIndex - 1][NEXT] = viewToDetach[NEXT] as LView;
} }
views.splice(removeIndex, 1); views.splice(removeIndex, 1);
if (!detached) { addRemoveViewFromContainer(viewToDetach, false);
addRemoveViewFromContainer(viewToDetach, false);
}
if (viewToDetach[QUERIES]) { if (viewToDetach[QUERIES]) {
viewToDetach[QUERIES] !.removeView(); viewToDetach[QUERIES] !.removeView();
@ -368,14 +365,11 @@ export function detachView(lContainer: LContainer, removeIndex: number, detached
* Removes a view from a container, i.e. detaches it and then destroys the underlying LView. * Removes a view from a container, i.e. detaches it and then destroys the underlying LView.
* *
* @param lContainer The container from which to remove a view * @param lContainer The container from which to remove a view
* @param tContainer The TContainer node associated with the LContainer
* @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, removeIndex: number) {
lContainer: LContainer, containerHost: TElementNode | TContainerNode | TElementContainerNode,
removeIndex: number) {
const view = lContainer[VIEWS][removeIndex]; const view = lContainer[VIEWS][removeIndex];
detachView(lContainer, removeIndex, !!containerHost.detached); detachView(lContainer, removeIndex);
destroyLView(view); destroyLView(view);
} }

View File

@ -264,13 +264,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._hostTNode, adjustedIdx); removeView(this._lContainer, 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);
const view = detachView(this._lContainer, adjustedIdx, !!this._hostTNode.detached); const view = detachView(this._lContainer, adjustedIdx);
const wasDetached = this._viewRefs.splice(adjustedIdx, 1)[0] != null; const wasDetached = this._viewRefs.splice(adjustedIdx, 1)[0] != null;
return wasDetached ? new ViewRef(view, view[CONTEXT], view[CONTAINER_INDEX]) : null; return wasDetached ? new ViewRef(view, view[CONTEXT], view[CONTAINER_INDEX]) : null;
} }