fix(ivy): DebugElement.triggerEventHandler not picking up events registered via Renderer2 (#31845)
Fixes Ivy's `DebugElement.triggerEventHandler` to picking up events that have been registered through a `Renderer2`, unlike ViewEngine. This PR resolves FW-1480. PR Close #31845
This commit is contained in:

committed by
Alex Rickabaugh

parent
a610d12266
commit
184d270725
@ -377,11 +377,28 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
|
||||
}
|
||||
|
||||
triggerEventHandler(eventName: string, eventObj: any): void {
|
||||
this.listeners.forEach((listener) => {
|
||||
const node = this.nativeNode as any;
|
||||
const invokedListeners: Function[] = [];
|
||||
|
||||
this.listeners.forEach(listener => {
|
||||
if (listener.name === eventName) {
|
||||
listener.callback(eventObj);
|
||||
const callback = listener.callback;
|
||||
callback(eventObj);
|
||||
invokedListeners.push(callback);
|
||||
}
|
||||
});
|
||||
|
||||
// We need to check whether `eventListeners` exists, because it's something
|
||||
// that Zone.js only adds to `EventTarget` in browser environments.
|
||||
if (typeof node.eventListeners === 'function') {
|
||||
// Note that in Ivy we wrap event listeners with a call to `event.preventDefault` in some
|
||||
// cases. We use `Function` as a special token that gives us access to the actual event
|
||||
// listener.
|
||||
node.eventListeners(eventName).forEach((listener: Function) => {
|
||||
const unwrappedListener = listener(Function);
|
||||
return invokedListeners.indexOf(unwrappedListener) === -1 && unwrappedListener(eventObj);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,13 @@ function wrapListener(
|
||||
wrapWithPreventDefault: boolean): EventListener {
|
||||
// Note: we are performing most of the work in the listener function itself
|
||||
// to optimize listener registration.
|
||||
return function wrapListenerIn_markDirtyAndPreventDefault(e: Event) {
|
||||
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;
|
||||
}
|
||||
|
||||
// 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 =
|
||||
|
Reference in New Issue
Block a user