mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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
This commit is contained in:
committed by
Dylan Hunn
parent
b592cdab53
commit
89f044375f
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user