Skip to content

Commit 94f042b

Browse files
ocombemhevery
authored andcommitted
refactor(ivy): remove unneeded detach property (angular#28595)
PR Close angular#28595
1 parent 9d10992 commit 94f042b

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

packages/core/src/render3/i18n.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,16 +854,15 @@ function removeNode(index: number, viewData: LView) {
854854
nativeRemoveNode(viewData[RENDERER], removedPhRNode);
855855
}
856856

857-
removedPhTNode.detached = true;
858-
ngDevMode && ngDevMode.rendererRemoveNode++;
859-
860857
const slotValue = load(index) as RElement | RComment | LContainer | StylingContext;
861858
if (isLContainer(slotValue)) {
862859
const lContainer = slotValue as LContainer;
863860
if (removedPhTNode.type !== TNodeType.Container) {
864861
nativeRemoveNode(viewData[RENDERER], lContainer[NATIVE]);
865862
}
866863
}
864+
865+
ngDevMode && ngDevMode.rendererRemoveNode++;
867866
}
868867

869868
/**

packages/core/src/render3/instructions.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,6 @@ export function createTNode(
12871287
next: null,
12881288
child: null,
12891289
parent: tParent,
1290-
detached: null,
12911290
stylingTemplate: null,
12921291
projection: null
12931292
};
@@ -2240,7 +2239,7 @@ export function containerRefreshEnd(): void {
22402239

22412240
// remove extra views at the end of the container
22422241
while (nextIndex < lContainer[VIEWS].length) {
2243-
removeView(lContainer, previousOrParentTNode as TContainerNode, nextIndex);
2242+
removeView(lContainer, nextIndex);
22442243
}
22452244
}
22462245

@@ -2271,22 +2270,19 @@ function refreshDynamicEmbeddedViews(lView: LView) {
22712270
* Removes views that need to be deleted in the process.
22722271
*
22732272
* @param lContainer to search for views
2274-
* @param tContainerNode to search for views
22752273
* @param startIdx starting index in the views array to search from
22762274
* @param viewBlockId exact view block id to look for
22772275
* @returns index of a found view or -1 if not found
22782276
*/
2279-
function scanForView(
2280-
lContainer: LContainer, tContainerNode: TContainerNode, startIdx: number,
2281-
viewBlockId: number): LView|null {
2277+
function scanForView(lContainer: LContainer, startIdx: number, viewBlockId: number): LView|null {
22822278
const views = lContainer[VIEWS];
22832279
for (let i = startIdx; i < views.length; i++) {
22842280
const viewAtPositionId = views[i][TVIEW].id;
22852281
if (viewAtPositionId === viewBlockId) {
22862282
return views[i];
22872283
} else if (viewAtPositionId < viewBlockId) {
22882284
// found a view that should not be at this position - remove
2289-
removeView(lContainer, tContainerNode, i);
2285+
removeView(lContainer, i);
22902286
} else {
22912287
// found a view with id greater than the one we are searching for
22922288
// 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
23132309
const lContainer = lView[containerTNode.index] as LContainer;
23142310

23152311
ngDevMode && assertNodeType(containerTNode, TNodeType.Container);
2316-
let viewToRender = scanForView(
2317-
lContainer, containerTNode as TContainerNode, lContainer[ACTIVE_INDEX] !, viewBlockId);
2312+
let viewToRender = scanForView(lContainer, lContainer[ACTIVE_INDEX] !, viewBlockId);
23182313

23192314
if (viewToRender) {
23202315
setIsParent(true);

packages/core/src/render3/interfaces/node.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,6 @@ export interface TNode {
304304
*/
305305
parent: TElementNode|TContainerNode|null;
306306

307-
/**
308-
* If this node is part of an i18n block, it indicates whether this node is part of the DOM.
309-
* If this node is not part of an i18n block, this field is null.
310-
*/
311-
detached: boolean|null;
312-
313307
stylingTemplate: StylingContext|null;
314308
/**
315309
* List of projected TNodes for a given component host element OR index into the said nodes.

packages/core/src/render3/node_manipulation.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,19 +340,16 @@ export function insertView(
340340
*
341341
* @param lContainer The container from which to detach a view
342342
* @param removeIndex The index of the view to detach
343-
* @param detached Whether or not this view is already detached.
344343
* @returns Detached LView instance.
345344
*/
346-
export function detachView(lContainer: LContainer, removeIndex: number, detached: boolean): LView {
345+
export function detachView(lContainer: LContainer, removeIndex: number): LView {
347346
const views = lContainer[VIEWS];
348347
const viewToDetach = views[removeIndex];
349348
if (removeIndex > 0) {
350349
views[removeIndex - 1][NEXT] = viewToDetach[NEXT] as LView;
351350
}
352351
views.splice(removeIndex, 1);
353-
if (!detached) {
354-
addRemoveViewFromContainer(viewToDetach, false);
355-
}
352+
addRemoveViewFromContainer(viewToDetach, false);
356353

357354
if (viewToDetach[QUERIES]) {
358355
viewToDetach[QUERIES] !.removeView();
@@ -368,14 +365,11 @@ export function detachView(lContainer: LContainer, removeIndex: number, detached
368365
* Removes a view from a container, i.e. detaches it and then destroys the underlying LView.
369366
*
370367
* @param lContainer The container from which to remove a view
371-
* @param tContainer The TContainer node associated with the LContainer
372368
* @param removeIndex The index of the view to remove
373369
*/
374-
export function removeView(
375-
lContainer: LContainer, containerHost: TElementNode | TContainerNode | TElementContainerNode,
376-
removeIndex: number) {
370+
export function removeView(lContainer: LContainer, removeIndex: number) {
377371
const view = lContainer[VIEWS][removeIndex];
378-
detachView(lContainer, removeIndex, !!containerHost.detached);
372+
detachView(lContainer, removeIndex);
379373
destroyLView(view);
380374
}
381375

packages/core/src/render3/view_engine_compatibility.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ export function createContainerRef(
264264

265265
remove(index?: number): void {
266266
const adjustedIdx = this._adjustIndex(index, -1);
267-
removeView(this._lContainer, this._hostTNode, adjustedIdx);
267+
removeView(this._lContainer, adjustedIdx);
268268
this._viewRefs.splice(adjustedIdx, 1);
269269
}
270270

271271
detach(index?: number): viewEngine_ViewRef|null {
272272
const adjustedIdx = this._adjustIndex(index, -1);
273-
const view = detachView(this._lContainer, adjustedIdx, !!this._hostTNode.detached);
273+
const view = detachView(this._lContainer, adjustedIdx);
274274
const wasDetached = this._viewRefs.splice(adjustedIdx, 1)[0] != null;
275275
return wasDetached ? new ViewRef(view, view[CONTEXT], view[CONTAINER_INDEX]) : null;
276276
}

0 commit comments

Comments
 (0)