@flexbase/observable-subject
Advanced tools
| import { SubscriptionDispatcher } from './subscription.dispatcher.js'; | ||
| import { SubscriptionContext } from './subscription.context.js'; | ||
| import { SubscriptionCallback } from './subscription.callback.js'; | ||
| export declare class MulticastDispatcher<T> implements SubscriptionDispatcher<T> { | ||
| dispatch(context: SubscriptionContext<T>, callbacks: SubscriptionCallback<T>[]): Promise<void>; | ||
| } | ||
| /** Represents a global multicast dispatcher instance */ | ||
| export declare const multicastDispatcher: MulticastDispatcher<unknown>; | ||
| export declare const multicastDispatcher: SubscriptionDispatcher; |
@@ -19,3 +19,3 @@ import { Logger } from '@flexbase/logger'; | ||
| */ | ||
| register(subject: Subject, dispatcher?: SubscriptionDispatcher<unknown>): boolean; | ||
| register(subject: Subject, dispatcher?: SubscriptionDispatcher): boolean; | ||
| /** | ||
@@ -22,0 +22,0 @@ * Checks if a subject is registered with this manager |
| import { SubscriptionContext } from './subscription.context.js'; | ||
| /** Represents a subscription callback method */ | ||
| export type SubscriptionCallback<T> = (context: SubscriptionContext<T>) => Promise<void>; | ||
| /** | ||
| * Represents a subscription callback method | ||
| * @param context - The context of the subscription notification | ||
| */ | ||
| export type SubscriptionCallback<T> = (context: SubscriptionContext<T>) => Promise<void> | void; |
@@ -1,5 +0,7 @@ | ||
| /** Represents the context sent to subscriptions on a notification */ | ||
| export interface SubscriptionContext<T> { | ||
| /** The value of the context */ | ||
| /** | ||
| * Represents the context sent to subscriptions on a notification | ||
| */ | ||
| export type SubscriptionContext<T> = { | ||
| /** The value of the subscription context */ | ||
| value: Readonly<T>; | ||
| } | ||
| }; |
| import { SubscriptionCallback } from './subscription.callback.js'; | ||
| import { SubscriptionContext } from './subscription.context.js'; | ||
| /** Represents a subscription dispatcher */ | ||
| export interface SubscriptionDispatcher<T> { | ||
| /** | ||
| * Handles dispatching the subscription callbacks | ||
| * @param context The context sent to each subscription | ||
| * @param callbacks The subscription callbacks that are to be notified | ||
| */ | ||
| dispatch(context: SubscriptionContext<T>, callbacks: SubscriptionCallback<T>[]): Promise<void>; | ||
| } | ||
| export type SubscriptionDispatcher = | ||
| /** | ||
| * Handles dispatching the subscription callbacks | ||
| * @param context The context sent to each subscription | ||
| * @param callbacks The subscription callbacks that are to be notified | ||
| */ | ||
| <T>(context: SubscriptionContext<T>, callbacks: SubscriptionCallback<T>[]) => Promise<void>; |
+1
-1
@@ -6,3 +6,3 @@ export { Subject } from './core/subject.interface.js'; | ||
| export { SubscriptionDispatcher } from './core/subscription.dispatcher.js'; | ||
| export { multicastDispatcher, MulticastDispatcher } from './core/multicast.dispatcher.js'; | ||
| export { multicastDispatcher } from './core/multicast.dispatcher.js'; | ||
| export { SubscriptionCallback } from './core/subscription.callback.js'; |
+10
-14
@@ -15,10 +15,6 @@ var a = Object.defineProperty; | ||
| } | ||
| const p = new g(); | ||
| const p = new g(), l = async (i, e) => { | ||
| await Promise.allSettled(e.map((s) => s(i))); | ||
| }; | ||
| class h { | ||
| async dispatch(e, s) { | ||
| await Promise.allSettled(s.map((t) => t(e))); | ||
| } | ||
| } | ||
| const l = new h(); | ||
| class y { | ||
| constructor(e, s) { | ||
@@ -40,3 +36,3 @@ o(this, "_subscription"); | ||
| } | ||
| class k { | ||
| class y { | ||
| constructor(e) { | ||
@@ -77,2 +73,3 @@ o(this, "_logger"); | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| _subscribe(e, s) { | ||
@@ -88,3 +85,3 @@ var n; | ||
| } | ||
| }, r = new y(c, s); | ||
| }, r = new h(c, s); | ||
| return t.subscriptions.push(r), r.subscription; | ||
@@ -147,12 +144,11 @@ } | ||
| const c = t.subscriptions.map((n) => n.callback); | ||
| await t.dispatcher.dispatch(s, c); | ||
| await t.dispatcher(s, c); | ||
| } | ||
| } | ||
| const S = new k(); | ||
| const _ = new y(); | ||
| export { | ||
| h as MulticastDispatcher, | ||
| k as SubjectManager, | ||
| y as SubjectManager, | ||
| l as multicastDispatcher, | ||
| p as noopSubscription, | ||
| S as subjectManager | ||
| _ as subjectManager | ||
| }; |
+1
-1
| { | ||
| "name": "@flexbase/observable-subject", | ||
| "version": "2.0.1", | ||
| "version": "2.1.0", | ||
| "description": "Observable subject event bus", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
12731
-2.35%264
-1.86%