Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uxland/event-aggregator

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uxland/event-aggregator

Event Aggregator

  • 1.0.1-alpha.17
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
51
decreased by-5.56%
Maintainers
2
Weekly downloads
 
Created
Source

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);

FAQs

Package last updated on 03 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc