Listeners

Module with methods that wraps native EventListener

on — add DOM event listener

off — remove DOM event listener

On

sets up native EventListener and saves to the Listeners storage

Parameters

HTMLElement event listener HTML element
String event type (click, keyup etc)
Function event callback
Boolean use capturing

Return value

Method does not return anything

on(element: HTMLElement, eventType: string, handler: () => void, useCapture?: boolean): void

Example

class MyTool { constructor({data, api}){ this.api = api; this.button = document.createElement('div'); } myMethod() { this.api.listeners.on(this.button, 'click', () => { console.log('Button clicked!'); }, false); } }

Off

disables EventListener and removes from Listeners storage

Parameters

HTMLElement event listener HTML element
String event type (click, keydown etc)
Function event callback

Return value

Method does not return anything

off(element: HTMLElement, eventType: string, handler: () => void): void

Example

class MyTool { constructor({data, api}){ this.api = api; this.button = document.createElement('div'); } myMethod() { this.api.listeners.on(this.button, 'click', () => { console.log('Button clicked!'); }, false); } destroy() { this.api.listeners.off(this.button, 'click', () => { console.log('Button clicked!'); }, false); } }