Table of contents

Listeners

Module with methods that wraps native EventListener

on — add DOM event listener

off — remove DOM event listener

sets up native EventListener and saves to the Listeners storage

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

Method does not return anything

on(element: HTMLElement, eventType: string, handler: () => void, useCapture?: boolean): void
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); } }

disables EventListener and removes from Listeners storage

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

Method does not return anything

off(element: HTMLElement, eventType: string, handler: () => void): void
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); } }