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 - npm Package Compare versions

Comparing version 1.0.0-alpha.17 to 1.0.0-alpha.18

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [1.0.0-alpha.18](https://github.com/uxland/uxland/compare/@uxland/event-aggregator@1.0.0-alpha.17...@uxland/event-aggregator@1.0.0-alpha.18) (2021-03-09)
### Bug Fixes
* **event-aggregator:** update testing and documentation ([208642b](https://github.com/uxland/uxland/commit/208642b6842ad11eda420d9df890ac7008d10069))
# [1.0.0-alpha.17](https://github.com/uxland/uxland/compare/@uxland/event-aggregator@1.0.0-alpha.16...@uxland/event-aggregator@1.0.0-alpha.17) (2021-03-02)

@@ -8,0 +19,0 @@

2

dist/index.js

@@ -1,2 +0,2 @@

// Event Aggregator v1.0.0-alpha.16
// Event Aggregator v1.0.0-alpha.17
// https://github.com/uxland/uxland/tree/master/packages/event-aggregator#readme

@@ -3,0 +3,0 @@ // (c) 2020-2021 UXLand

@@ -5,9 +5,70 @@ export interface Subscription {

export declare type EventCallback = (data: any, event?: string) => void;
declare class EventAggregator {
/**
* Subscribes to a message channel or message type
* @memberof EventAggregator
* @class
* @since v1.0.0
* @example
*
* ```
* const EA = new EventAggregator();
* EA.subscribe('event', () => {...});
* EA.publish('event');
* ```
*
*/
export declare class EventAggregator {
eventLookup: Record<string, any[]>;
messageHandlers: Array<any>;
constructor();
publish(event: string, data: any): void | never;
subscribe(event: string, callback: EventCallback): Subscription;
subscribeOnce(event: string, callback: EventCallback): Subscription;
/**
* Publishes a message
* @function
* @memberof EventAggregator.EventAggregator
* @name publish
* @param {string} event The event or channel to publish to
* @param {*} data The data to publish on the channel
* @returns {void|never}
* @throws Event channel/type is invalid
* @example
*
* const payload = { foo: 'bar' };
* publish('EVENT-ID', payload);
*
*/
publish(event: string | any, data: any): void | never;
/**
* Subscribes to a message channel or message type
* @function
* @memberof EventAggregator.EventAggregator
* @name subscribe
* @param {string} event The event channel or event data type
* @param {EventAggregator.EventCallback} callback The callback to be invoked when when the specified message is published
* @returns {EventAggregator.Subscription}
* @throws Event channel/type is invalid
* @example
*
* ```
* EA.subscribe('EVENT-ID', callback);
* ```
*
*/
subscribe(event: string | any, callback: EventCallback): Subscription;
/**
* Subscribes to a message channel or message type, then disposes the subscription automatically after the first message is received
* @function
* @memberof EventAggregator.EventAggregator
* @name subscribeOnce
* @param {string} event The event channel or event data type
* @param {EventAggregator.EventCallback} callback The callback to be invoked when when the specified message is published
* @returns {EventAggregator.Subscription}
* @example
*
* ```
* const callback = (payload: any): void => {};
* EA.subscribeOnce('EVENT-ID', callback);
* ```
*
*/
subscribeOnce(event: string | any, callback: EventCallback): Subscription;
}

@@ -76,2 +137,1 @@ /**

export declare const publish: any;
export {};

@@ -64,3 +64,17 @@ /*

};
class EventAggregator {
/**
* Subscribes to a message channel or message type
* @memberof EventAggregator
* @class
* @since v1.0.0
* @example
*
* ```
* const EA = new EventAggregator();
* EA.subscribe('event', () => {...});
* EA.publish('event');
* ```
*
*/
export class EventAggregator {
constructor() {

@@ -70,2 +84,17 @@ this.eventLookup = {};

}
/**
* Publishes a message
* @function
* @memberof EventAggregator.EventAggregator
* @name publish
* @param {string} event The event or channel to publish to
* @param {*} data The data to publish on the channel
* @returns {void|never}
* @throws Event channel/type is invalid
* @example
*
* const payload = { foo: 'bar' };
* publish('EVENT-ID', payload);
*
*/
publish(event, data) {

@@ -95,2 +124,18 @@ let subscribers;

}
/**
* Subscribes to a message channel or message type
* @function
* @memberof EventAggregator.EventAggregator
* @name subscribe
* @param {string} event The event channel or event data type
* @param {EventAggregator.EventCallback} callback The callback to be invoked when when the specified message is published
* @returns {EventAggregator.Subscription}
* @throws Event channel/type is invalid
* @example
*
* ```
* EA.subscribe('EVENT-ID', callback);
* ```
*
*/
subscribe(event, callback) {

@@ -120,2 +165,18 @@ let handler;

}
/**
* Subscribes to a message channel or message type, then disposes the subscription automatically after the first message is received
* @function
* @memberof EventAggregator.EventAggregator
* @name subscribeOnce
* @param {string} event The event channel or event data type
* @param {EventAggregator.EventCallback} callback The callback to be invoked when when the specified message is published
* @returns {EventAggregator.Subscription}
* @example
*
* ```
* const callback = (payload: any): void => {};
* EA.subscribeOnce('EVENT-ID', callback);
* ```
*
*/
subscribeOnce(event, callback) {

@@ -122,0 +183,0 @@ const sub = this.subscribe(event, (a, b) => {

@@ -5,9 +5,70 @@ export interface Subscription {

export declare type EventCallback = (data: any, event?: string) => void;
declare class EventAggregator {
/**
* Subscribes to a message channel or message type
* @memberof EventAggregator
* @class
* @since v1.0.0
* @example
*
* ```
* const EA = new EventAggregator();
* EA.subscribe('event', () => {...});
* EA.publish('event');
* ```
*
*/
export declare class EventAggregator {
eventLookup: Record<string, any[]>;
messageHandlers: Array<any>;
constructor();
publish(event: string, data: any): void | never;
subscribe(event: string, callback: EventCallback): Subscription;
subscribeOnce(event: string, callback: EventCallback): Subscription;
/**
* Publishes a message
* @function
* @memberof EventAggregator.EventAggregator
* @name publish
* @param {string} event The event or channel to publish to
* @param {*} data The data to publish on the channel
* @returns {void|never}
* @throws Event channel/type is invalid
* @example
*
* const payload = { foo: 'bar' };
* publish('EVENT-ID', payload);
*
*/
publish(event: string | any, data: any): void | never;
/**
* Subscribes to a message channel or message type
* @function
* @memberof EventAggregator.EventAggregator
* @name subscribe
* @param {string} event The event channel or event data type
* @param {EventAggregator.EventCallback} callback The callback to be invoked when when the specified message is published
* @returns {EventAggregator.Subscription}
* @throws Event channel/type is invalid
* @example
*
* ```
* EA.subscribe('EVENT-ID', callback);
* ```
*
*/
subscribe(event: string | any, callback: EventCallback): Subscription;
/**
* Subscribes to a message channel or message type, then disposes the subscription automatically after the first message is received
* @function
* @memberof EventAggregator.EventAggregator
* @name subscribeOnce
* @param {string} event The event channel or event data type
* @param {EventAggregator.EventCallback} callback The callback to be invoked when when the specified message is published
* @returns {EventAggregator.Subscription}
* @example
*
* ```
* const callback = (payload: any): void => {};
* EA.subscribeOnce('EVENT-ID', callback);
* ```
*
*/
subscribeOnce(event: string | any, callback: EventCallback): Subscription;
}

@@ -76,2 +137,1 @@ /**

export declare const publish: any;
export {};

@@ -20,3 +20,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.publish = exports.subscribeOnce = exports.subscribe = exports.eventAggregator = void 0;
exports.publish = exports.subscribeOnce = exports.subscribe = exports.eventAggregator = exports.EventAggregator = void 0;
let STUB = 1;

@@ -68,2 +68,16 @@ /**

};
/**
* Subscribes to a message channel or message type
* @memberof EventAggregator
* @class
* @since v1.0.0
* @example
*
* ```
* const EA = new EventAggregator();
* EA.subscribe('event', () => {...});
* EA.publish('event');
* ```
*
*/
class EventAggregator {

@@ -74,2 +88,17 @@ constructor() {

}
/**
* Publishes a message
* @function
* @memberof EventAggregator.EventAggregator
* @name publish
* @param {string} event The event or channel to publish to
* @param {*} data The data to publish on the channel
* @returns {void|never}
* @throws Event channel/type is invalid
* @example
*
* const payload = { foo: 'bar' };
* publish('EVENT-ID', payload);
*
*/
publish(event, data) {

@@ -99,2 +128,18 @@ let subscribers;

}
/**
* Subscribes to a message channel or message type
* @function
* @memberof EventAggregator.EventAggregator
* @name subscribe
* @param {string} event The event channel or event data type
* @param {EventAggregator.EventCallback} callback The callback to be invoked when when the specified message is published
* @returns {EventAggregator.Subscription}
* @throws Event channel/type is invalid
* @example
*
* ```
* EA.subscribe('EVENT-ID', callback);
* ```
*
*/
subscribe(event, callback) {

@@ -124,2 +169,18 @@ let handler;

}
/**
* Subscribes to a message channel or message type, then disposes the subscription automatically after the first message is received
* @function
* @memberof EventAggregator.EventAggregator
* @name subscribeOnce
* @param {string} event The event channel or event data type
* @param {EventAggregator.EventCallback} callback The callback to be invoked when when the specified message is published
* @returns {EventAggregator.Subscription}
* @example
*
* ```
* const callback = (payload: any): void => {};
* EA.subscribeOnce('EVENT-ID', callback);
* ```
*
*/
subscribeOnce(event, callback) {

@@ -133,2 +194,3 @@ const sub = this.subscribe(event, (a, b) => {

}
exports.EventAggregator = EventAggregator;
/**

@@ -135,0 +197,0 @@ * Event Aggregator singleton

{
"name": "@uxland/event-aggregator",
"version": "1.0.0-alpha.17",
"version": "1.0.0-alpha.18",
"description": "Event Aggregator",

@@ -75,3 +75,3 @@ "author": "UXLand <dev@uxland.es>",

},
"gitHead": "94ab2350f3cf7a6a07f9ef3b89354c2b4e3a1655"
"gitHead": "7246afa3fbcdd1c593ea0b7368513c837cd248a7"
}

@@ -5,3 +5,3 @@ # UXL Event Aggregator [![npm version](https://badge.fury.io/js/%40uxland%2Fevent-aggregator.svg)](https://badge.fury.io/js/%40uxland%2Fevent-aggregator)

| ----------------------------------------------- | --------------------------------------------- | ----------------------------------------- | ------------------------------------------- | ----------------------------------- |
| ![BuildStatus](https://img.shields.io/badge/Build-Passing-brightgreen.svg "Building Status") | ![Statements](https://img.shields.io/badge/Coverage-40%25-red.svg "Make me better!") | ![Branches](https://img.shields.io/badge/Coverage-31.25%25-red.svg "Make me better!") | ![Functions](https://img.shields.io/badge/Coverage-30%25-red.svg "Make me better!") | ![Lines](https://img.shields.io/badge/Coverage-40%25-red.svg "Make me better!") |
| ![BuildStatus](https://img.shields.io/badge/Build-Passing-brightgreen.svg "Building Status") | ![Statements](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg "Make me better!") | ![Branches](https://img.shields.io/badge/Coverage-81.25%25-yellow.svg "Make me better!") | ![Functions](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg "Make me better!") | ![Lines](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg "Make me better!") |

@@ -14,2 +14,16 @@ ## Installation

### 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.
```typescript
const EA = new EventAggregator();
const EA2 = new EventAggregator();
EA.subscribe('event', () => {...});
EA2.subscribe('event2', () => {...});
EA.subscribe('common-event', () => {...});
EA2.subscribe('common-event', () => {...});
```
### Event publish

@@ -20,6 +34,14 @@

```typescript
const payload = { foo: 'bar' };
publish('EVENT-ID', payload);
const payload = { foo: "bar" };
publish("EVENT-ID", payload);
```
It is possible also to provide a class instead of a string event
```typescript
publish(new Klass(), callback);
```
If a subscription is done with provided class, the callback provided at the subscription moment will be called.
### Event subscription

@@ -31,5 +53,11 @@

const callback = (payload: any): void => {};
subscribe('EVENT-ID', callback);
subscribe("EVENT-ID", callback);
```
It is possible also to provide a class instead of a string event
```typescript
subscribe(Klass, callback);
```
### Event subscription (only once)

@@ -41,3 +69,3 @@

const callback = (payload: any): void => {};
subscribeOnce('EVENT-ID', callback);
subscribeOnce("EVENT-ID", callback);
```
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