1.0.1 • Published 2 years ago

@uxland/event-aggregator v1.0.1

Weekly downloads
8
License
BSD-4-Clause
Repository
github
Last release
2 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

2 years ago

1.0.1-alpha.22

2 years ago

1.0.1-alpha.21

2 years ago

1.0.1-alpha.20

3 years ago

1.0.1-alpha.15

3 years ago

1.0.1-alpha.14

3 years ago

1.0.1-alpha.13

3 years ago

1.0.1-alpha.19

3 years ago

1.0.1-alpha.18

3 years ago

1.0.1-alpha.17

3 years ago

1.0.1-alpha.16

3 years ago

1.0.1-alpha.12

3 years ago

1.0.1-alpha.11

3 years ago

1.0.1-alpha.9

3 years ago

1.0.1-alpha.8

3 years ago

1.0.1-alpha.10

3 years ago

1.0.1-alpha.7

3 years ago

1.0.1-alpha.6

3 years ago

1.0.1-alpha.5

3 years ago

1.0.1-alpha.4

3 years ago

1.0.1-alpha.3

3 years ago

1.0.0

3 years ago

1.0.0-alpha.19

3 years ago

1.0.1-alpha.2

3 years ago

1.0.1-alpha.1

3 years ago

1.0.1-alpha.0

3 years ago

1.0.0-alpha.18

3 years ago

1.0.0-alpha.17

3 years ago

1.0.0-alpha.16

3 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

4 years ago

1.0.0-alpha.9

4 years ago

1.0.0-alpha.8

4 years ago

1.0.0-alpha.7

4 years ago

1.0.0-alpha.6

4 years ago

1.0.0-alpha.5

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.2

4 years ago

1.0.0-alpha.1

4 years ago

1.0.0-alpha.0

4 years ago