From defefae4b5a0ed064ba1b55e27955999eced7099 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Thu, 20 Mar 2025 13:08:52 +0100 Subject: [PATCH] refactor(core): remove special-casing from listener wrapping (#60549) We had a special case in the `wrapListener` function that would return the original function if it's invoked with `Function`. This was added for `DebugNode.triggerEventHandler`, but isn't necessary anymore. PR Close #60549 --- packages/core/src/render3/view/listeners.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/core/src/render3/view/listeners.ts b/packages/core/src/render3/view/listeners.ts index dbb4ae21a05..4c08d7bd3a5 100644 --- a/packages/core/src/render3/view/listeners.ts +++ b/packages/core/src/render3/view/listeners.ts @@ -35,26 +35,20 @@ export function wrapListener( ): EventListener { // Note: we are performing most of the work in the listener function itself // to optimize listener registration. - return function wrapListenerIn_markDirtyAndPreventDefault(e: any) { - // Ivy uses `Function` as a special token that allows us to unwrap the function - // so that it can be invoked programmatically by `DebugNode.triggerEventHandler`. - if (e === Function) { - return listenerFn; - } - + return function wrapListenerIn_markDirtyAndPreventDefault(event: any) { // In order to be backwards compatible with View Engine, events on component host nodes // must also mark the component view itself dirty (i.e. the view that it owns). const startView = isComponentHost(tNode) ? getComponentLViewByIndex(tNode.index, lView) : lView; markViewDirty(startView, NotificationSource.Listener); const context = lView[CONTEXT]; - let result = executeListenerWithErrorHandling(lView, context, listenerFn, e); + let result = executeListenerWithErrorHandling(lView, context, listenerFn, event); // A just-invoked listener function might have coalesced listeners so we need to check for // their presence and invoke as needed. let nextListenerFn = (wrapListenerIn_markDirtyAndPreventDefault).__ngNextListenerFn__; while (nextListenerFn) { // We should prevent default if any of the listeners explicitly return false - result = executeListenerWithErrorHandling(lView, context, nextListenerFn, e) && result; + result = executeListenerWithErrorHandling(lView, context, nextListenerFn, event) && result; nextListenerFn = (nextListenerFn).__ngNextListenerFn__; }