fix(ivy): ensure eventListeners added outside angular context are not called... (#34514)

by DebugElement.triggerEventHandler. ZoneJS tracks the eventListeners on
a node but we need to be able to differentiate between those added by
Angular and those that were added outside the Angular context. This fix
aligns with the behavior that was present in View Engine (not calling
those listeners). If we decide later that we want to call those
listeners, we still need a way to differentiate between those that
we have wrapped in dom_renderer and those that were not (because they
were added outside the Angular context).

PR Close #34514
This commit is contained in:
Andrew Scott
2019-12-20 10:20:59 -08:00
committed by Andrew Kushnir
parent d15cf60c49
commit 32b72f39f0
3 changed files with 42 additions and 8 deletions

View File

@ -50,10 +50,16 @@ export function flattenStyles(
}
function decoratePreventDefault(eventHandler: Function): Function {
// `DebugNode.triggerEventHandler` needs to know if the listener was created with
// decoratePreventDefault or is a listener added outside the Angular context so it can handle the
// two differently. In the first case, the special '__ngUnwrap__' token is passed to the unwrap
// the listener (see below).
return (event: 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 (event === Function) {
// Ivy uses '__ngUnwrap__' as a special token that allows us to unwrap the function
// so that it can be invoked programmatically by `DebugNode.triggerEventHandler`. The debug_node
// can inspect the listener toString contents for the existence of this special token. Because
// the token is a string literal, it is ensured to not be modified by compiled code.
if (event === '__ngUnwrap__') {
return eventHandler;
}