UNPKG

@broadcaster/core

Version:

Cross window serverless messaging system based on BroadcastChannel API. Allows to send messages and keep track about instances between browsing contexts (tabs, windows, workers, etc..)

57 lines (56 loc) 1.76 kB
type GenericSubscriberCallback<P extends Array<unknown>> = (...args: P) => void; type Subscriber<CallbackArguments extends Array<unknown>> = { next: GenericSubscriberCallback<CallbackArguments>; onComplete: GenericSubscriberCallback<never[]> | undefined; }; type Subscription = { unsubscribe: () => void; }; /** * **Broadcaster Subscription** * * Manages subscriptions and life cycle of all subscribers. * * @private * @param CallbackArguments type definition of a subscriber callback arguments */ export declare class BroadcasterSubscription<CallbackArguments extends Array<unknown>> { /** * List of all currently active subscribers */ private subscribers; /** * When shareReplay is true, it will store the latest value */ private buffer?; /** * If true, it will resend the latest message to a new subscriber */ private shareReplay; constructor(shareReplay?: boolean); /** * Close channel and notify subscribers */ close: () => void; /** * Push a payload to all subscribers. * * @param args subscriber callback attributes */ next: GenericSubscriberCallback<CallbackArguments>; /** * Subscribes to a channel * * @param callback method called every time new payload occurs. * @param complete method called, when channel is closed * @returns subscription info object with teardown function */ subscribe: (callback: Subscriber<CallbackArguments>["next"], complete?: Subscriber<CallbackArguments>["onComplete"]) => Subscription; /** * Unsubscribes from a channel * * @param callback */ unsubscribe: (callback: GenericSubscriberCallback<CallbackArguments>) => void; } export {};