Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): get event listeners needs to be embedded during the build… #206

Open
wants to merge 2 commits into
base: 4.x.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions libs/core/src/lib/@types/geteventlisteners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
interface IEventListener<K extends keyof ElementEventMap> {
type: K;
listener: (ev: ElementEventMap[K]) => void;
options?: boolean | EventListenerOptions;
}

type IEventListenerArray<K extends keyof ElementEventMap> = IEventListener<K>[];

type IEventListenersMap<K extends keyof ElementEventMap> = Record<K, IEventListenerArray<K>>;

interface HTMLElement {
/**
* Gets all the event listeners of the element.
*/
getEventListeners<K extends keyof ElementEventMap>(): IEventListenersMap<K>;

/**
* Gets all the event listeners of a type of the element.
*/
getEventListeners<K extends keyof ElementEventMap>(type?: K): IEventListenerArray<K>;
}
3 changes: 2 additions & 1 deletion libs/core/src/lib/components/wrapper-component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
/// <reference path="../renderer/geteventlisteners.ts" />
import '../@types/geteventlisteners';


import { AfterViewInit, ChangeDetectorRef, ElementRef, Input, NgZone, OnChanges, Renderer2, SimpleChanges, AfterContentInit, Directive } from '@angular/core';
import classnames from 'classnames';
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/lib/renderer/geteventlisteners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Element.prototype.removeEventListener = function<K extends keyof ElementEventMap
if (this.eventListenerList[type].length == 0) delete this.eventListenerList[type];
};

Element.prototype.getEventListeners = function<K extends keyof ElementEventMap>(type?: K) {
HTMLElement.prototype.getEventListeners = function<K extends keyof ElementEventMap>(type?: K) {
if (!this.eventListenerList) this.eventListenerList = {};

// return requested listeners type or all them
Expand Down