diff --git a/libs/core/src/lib/@types/geteventlisteners.ts b/libs/core/src/lib/@types/geteventlisteners.ts new file mode 100644 index 0000000..da32bd7 --- /dev/null +++ b/libs/core/src/lib/@types/geteventlisteners.ts @@ -0,0 +1,21 @@ +interface IEventListener { + type: K; + listener: (ev: ElementEventMap[K]) => void; + options?: boolean | EventListenerOptions; +} + +type IEventListenerArray = IEventListener[]; + +type IEventListenersMap = Record>; + +interface HTMLElement { + /** + * Gets all the event listeners of the element. + */ + getEventListeners(): IEventListenersMap; + + /** + * Gets all the event listeners of a type of the element. + */ + getEventListeners(type?: K): IEventListenerArray; +} diff --git a/libs/core/src/lib/components/wrapper-component.ts b/libs/core/src/lib/components/wrapper-component.ts index 9e1820a..f654f1d 100644 --- a/libs/core/src/lib/components/wrapper-component.ts +++ b/libs/core/src/lib/components/wrapper-component.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -/// +import '../@types/geteventlisteners'; + import { AfterViewInit, ChangeDetectorRef, ElementRef, Input, NgZone, OnChanges, Renderer2, SimpleChanges, AfterContentInit, Directive } from '@angular/core'; import classnames from 'classnames'; diff --git a/libs/core/src/lib/renderer/geteventlisteners.ts b/libs/core/src/lib/renderer/geteventlisteners.ts index 1889876..63783a2 100644 --- a/libs/core/src/lib/renderer/geteventlisteners.ts +++ b/libs/core/src/lib/renderer/geteventlisteners.ts @@ -85,7 +85,7 @@ Element.prototype.removeEventListener = function(type?: K) { +HTMLElement.prototype.getEventListeners = function(type?: K) { if (!this.eventListenerList) this.eventListenerList = {}; // return requested listeners type or all them