1.0.1 • Published 3 years ago

@uxland/event-aggregator v1.0.1

Weekly downloads
8
License
BSD-4-Clause
Repository
github
Last release
3 years ago

UXL Event Aggregator npm version

Build StatusStatementsBranchesFunctionsLines
BuildStatusStatementsBranchesFunctionsLines

Installation

npm i @uxland/event-aggregator

Usage

Event Aggregator instance

It is possible to define numerous instances of the Event Aggregator within a project, each one with the same or different events subscribed, simulating each instance as a new channel of communication.

const EA = new EventAggregator();
const EA2 = new EventAggregator();

EA.subscribe('event', () => {...});
EA2.subscribe('event2', () => {...});
EA.subscribe('common-event', () => {...});
EA2.subscribe('common-event', () => {...});

Event publish

To publish an event you must specify an eventId and an optional payload that will be collected by subscriber.

const payload = { foo: "bar" };
publish("EVENT-ID", payload);

It is possible also to provide a class instead of a string event

publish(new Klass(), callback);

If a subscription is done with provided class, the callback provided at the subscription moment will be called.

Event subscription

In order to subscribe to an event you must specify an eventId and a callback function that will be called when that event is received.

const callback = (payload: any): void => {};
subscribe("EVENT-ID", callback);

It is possible also to provide a class instead of a string event

subscribe(Klass, callback);

Event subscription (only once)

In order to subscribe to an event, only once, you must specify an eventId and a callback function that will be called when that event is received. For the next publishes of that event, this subscriber will not receive that event.

const callback = (payload: any): void => {};
subscribeOnce("EVENT-ID", callback);
1.0.1

3 years ago

1.0.1-alpha.22

3 years ago

1.0.1-alpha.21

3 years ago

1.0.1-alpha.20

4 years ago

1.0.1-alpha.15

4 years ago

1.0.1-alpha.14

4 years ago

1.0.1-alpha.13

4 years ago

1.0.1-alpha.19

4 years ago

1.0.1-alpha.18

4 years ago

1.0.1-alpha.17

4 years ago

1.0.1-alpha.16

4 years ago

1.0.1-alpha.12

4 years ago

1.0.1-alpha.11

4 years ago

1.0.1-alpha.9

4 years ago

1.0.1-alpha.8

4 years ago

1.0.1-alpha.10

4 years ago

1.0.1-alpha.7

4 years ago

1.0.1-alpha.6

4 years ago

1.0.1-alpha.5

4 years ago

1.0.1-alpha.4

4 years ago

1.0.1-alpha.3

4 years ago

1.0.0

4 years ago

1.0.0-alpha.19

4 years ago

1.0.1-alpha.2

4 years ago

1.0.1-alpha.1

4 years ago

1.0.1-alpha.0

4 years ago

1.0.0-alpha.18

4 years ago

1.0.0-alpha.17

4 years ago

1.0.0-alpha.16

4 years ago

1.0.0-alpha.15

4 years ago

1.0.0-alpha.14

4 years ago

1.0.0-alpha.13

4 years ago

1.0.0-alpha.12

4 years ago

1.0.0-alpha.11

4 years ago

1.0.0-alpha.10

5 years ago

1.0.0-alpha.9

5 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha.0

5 years ago