0.0.13 • Published 5 years ago

ab-event-emitter v0.0.13

Weekly downloads
11
License
ISC
Repository
github
Last release
5 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

5 years ago

0.0.12

5 years ago

0.0.13

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.3

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago