From 916406560b42572890dec15e36d868d05b4e6805 Mon Sep 17 00:00:00 2001 From: Florian Bouillon Date: Tue, 8 Dec 2020 16:07:50 +0100 Subject: [PATCH] Made Functions more clear Signed-off-by: Florian Bouillon --- packages/dom-manager/src/DOMElement.ts | 40 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/packages/dom-manager/src/DOMElement.ts b/packages/dom-manager/src/DOMElement.ts index 5a1549f..7da4d10 100644 --- a/packages/dom-manager/src/DOMElement.ts +++ b/packages/dom-manager/src/DOMElement.ts @@ -12,15 +12,24 @@ export default class DOMElement { this.item = document.createElement(tagName, options) as any } - public static create(tagName: K, options?: ElementCreationOptions): DOMElement; - public static create(tagName: string, options?: ElementCreationOptions): DOMElement { + public static create( + tagName: K, + options?: ElementCreationOptions + ): DOMElement + public static create( + tagName: string, + options?: ElementCreationOptions + ): DOMElement { return new DOMElement(tagName as Tags, options) } - public static get(query: string | T, source?: HTMLElement | DOMElement): DOMElement | undefined { + public static get( + query: string | GT, + source?: HTMLElement | DOMElement + ): DOMElement | undefined { if (!(query instanceof HTMLElement)) { - const tmp = (source instanceof DOMElement ? source.item : source || document).querySelector(query) + const tmp = (source instanceof DOMElement ? source.item : source || document).querySelector(query) if (!tmp) { return undefined } @@ -29,14 +38,29 @@ export default class DOMElement { return new DOMElement(query) } - public on(type: K, listener: (this: T, ev: HTMLElementEventMap[K]) => void, options?: boolean | AddEventListenerOptions): this - public on(type: string, listener: (this: T, ev: Event) => void, options?: boolean | AddEventListenerOptions): this - public on(type: string, listener: (this: T, ev: Event) => void, options?: boolean | AddEventListenerOptions) { + public on( + type: K, + listener: (this: T, ev: HTMLElementEventMap[K]) => void, + options?: boolean | AddEventListenerOptions + ): this + public on( + type: string, + listener: (this: T, ev: Event) => void, + options?: boolean | AddEventListenerOptions + ): this + public on( + type: string, + listener: (this: T, ev: Event) => void, + options?: boolean | AddEventListenerOptions + ) { this.item.addEventListener(type, listener, options) return this } - public off(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => void) { + public off( + type: K, + listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => void + ) { this.item.removeEventListener(type, listener) return this }