micromitter
minimal and performant event emitter / emitter with custom events and payload
API
Table of Contents
constructor
Creates an instance of MicroMitter.
Parameters
target
any the event target
on
adds an event handler to an event type
Parameters
Examples
emitter;
Returns MicroMitter self
off
removes either a specific handler or all handlers related to an event type
Parameters
Returns MicroMitter self
once
adds an event handler to an event type and immediately removes it after first event call
Parameters
Examples
emitter;
Returns MicroMitter self
emit
triggers an event for a specific type with an optional data object
Parameters
type
stringdata
any (optional, default{}
)
Examples
emitter;
Returns MicroMitter self
Usage
; const emitter = ; emitter; emitter;emitter; let counter = 0;emitter; emitter;emitter;emitter;emitter;console; // 1
chaining
emitter ;
use global instance
; emitter; emitter;
use decorator
; //v1: use es7 decorators@micromitter { console; console; } //v2 use the decorator as a function; const tt = ; tt;tt;