1.1.4 • Published 3 years ago

@superherocheesecake/event-dispatcher v1.1.4

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

EventDispatcher

Global EventDispatcher

NPM installation

npm i --save @superherocheesecake/event-dispatcher

Common practice

Most likely you will extend your own class.

import EventDispatcher from '@superherocheesecake/event-dispatcher';

class Module extends EventDispatcher {
    // ...
}

Methods

dispatchEvent(type, payload)

Payload can be any type of value.

this.dispatchEvent('eventName', {key: value});

addEventListener(type, listener)

this.addEventListener('eventName', listener);

addEventListenerOnce(type, listener)

this.addEventListenerOnce('eventName', listener);

removeEventListener(type, listener)

this.removeEventListener('eventName', listener);

hasEventListener(type, listener)

this.hasEventListener('eventName', listener);