UNPKG

sub-events

Version:

Lightweight, strongly-typed events, with monitored subscriptions.

44 lines (43 loc) 1.09 kB
/** * Represents an event subscription, and a safe way to cancel it. * * @see {@link cancel} */ export declare class Subscription { /** * @hidden */ private _cancel; /** * Subscription's `name` option, if it was set with method {@link SubEvent.subscribe}. */ readonly name?: string; /** * @hidden */ constructor(init: { cancel: () => void; sub: { cancel: () => void; name?: string; }; }); /** * Indicates whether the subscription is live / active. * * It can be useful to subscribers when {@link SubEvent.cancelAll} is used without their knowledge. */ get live(): boolean; /** * Cancels the live subscription. The subscriber won't receive any more events. * * It also sets flag {@link live} to `false`. * * @returns * - `true` - subscription has been successfully cancelled * - `false` - nothing happened, as subscription wasn't live * * @see {@link SubEvent.cancelAll} */ cancel(): boolean; }