0.0.13 • Published 4 years ago

ab-event-emitter v0.0.13

Weekly downloads
11
License
ISC
Repository
github
Last release
4 years ago

ab-event-emitter

Install

npm install ab-event-emitter

Usage

import { EventEmitter } from "ab-event-emitter";

const events = new EventEmitter();

events.on("message", (message) => {
  console.log(message);
});

events.emit("message", "something");
// console.log('something')

API

on(event: E, listener: (data: EventData) => void): () => void

Subscribe listener to event.

event - any string

listener - function that takes some data associated with event and returns void

<returned value> - function that you can call in order to unsubscribe

off(event: E, listener: (data: EventData) => void): EventEmitter

Unsubscribe listener from event.

event - any string

listener - function that takes some data associated with event and returns void

<returned value> - the event emitte.r

emit(event: E, data: EventData): EventEmitter

Calls all listeners with data passed as the first parameter

offAll(): EventEmitter

Unsubscribe from all events.

listenersNumber(event: E): number

Returns number of listeners subscribed to event

getListenedEvents(): (keyof EventConfig)[]

Returns array of events which have listeners

getListeners(event: E): ((data: EventData) => void)[]

Returns array of listeners assigned to event

0.0.11

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago