From 89f044375fa0d2630ac7aa9576e68ab291142892 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Mon, 14 Nov 2022 16:33:21 +0100 Subject: [PATCH] refactor(core): remove Renderer3-related cleanup code paths (#48046) Renderer3 had to store reference to the listener function in order to properly cleanup event listeners. Since the Renderer3 abstraction was removed the corresponding code path is no longer needed (Renderer2 returns a cleanup function that can be called directly). PR Close #48046 --- .../core/src/render3/node_manipulation.ts | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/core/src/render3/node_manipulation.ts b/packages/core/src/render3/node_manipulation.ts index 9d0db8e5a0d..995a166991e 100644 --- a/packages/core/src/render3/node_manipulation.ts +++ b/packages/core/src/render3/node_manipulation.ts @@ -9,7 +9,7 @@ import {ViewEncapsulation} from '../metadata/view'; import {RendererStyleFlags2} from '../render/api_flags'; import {addToArray, removeFromArray} from '../util/array_utils'; -import {assertDefined, assertEqual, assertFunction, assertString} from '../util/assert'; +import {assertDefined, assertEqual, assertFunction, assertNumber, assertString} from '../util/assert'; import {escapeCommentText} from '../util/dom'; import {assertLContainer, assertLView, assertParentView, assertProjectionSlots, assertTNodeForLView} from './assert'; @@ -451,24 +451,16 @@ function processCleanups(tView: TView, lView: LView): void { if (tCleanup !== null) { for (let i = 0; i < tCleanup.length - 1; i += 2) { if (typeof tCleanup[i] === 'string') { - // This is a native DOM listener - const idxOrTargetGetter = tCleanup[i + 1]; - const target = typeof idxOrTargetGetter === 'function' ? - idxOrTargetGetter(lView) : - unwrapRNode(lView[idxOrTargetGetter]); - const listener = lCleanup[lastLCleanupIndex = tCleanup[i + 2]]; - const useCaptureOrSubIdx = tCleanup[i + 3]; - if (typeof useCaptureOrSubIdx === 'boolean') { - // native DOM listener registered with Renderer3 - target.removeEventListener(tCleanup[i], listener, useCaptureOrSubIdx); + // This is a native DOM listener. It will occupy 4 entries in the TCleanup array (hence i += + // 2 at the end of this block). + const targetIdx = tCleanup[i + 3]; + ngDevMode && assertNumber(targetIdx, 'cleanup target must be a number'); + if (targetIdx >= 0) { + // unregister + lCleanup[lastLCleanupIndex = targetIdx](); } else { - if (useCaptureOrSubIdx >= 0) { - // unregister - lCleanup[lastLCleanupIndex = useCaptureOrSubIdx](); - } else { - // Subscription - lCleanup[lastLCleanupIndex = -useCaptureOrSubIdx].unsubscribe(); - } + // Subscription + lCleanup[lastLCleanupIndex = -targetIdx].unsubscribe(); } i += 2; } else {