ste-core
Version:
Core files for the Strongly Typed Events project.
99 lines (98 loc) • 3.07 kB
TypeScript
import { ISubscribable, SubscriptionChangeEventHandler } from "..";
/**
* Hides the implementation of the event dispatcher. Will expose methods that
* are relevent to the event.
*
* @export
* @class DispatcherWrapper
* @implements {ISubscribable<TEventHandler>}
* @template TEventHandler The type of event handler.
*/
export declare class DispatcherWrapper<TEventHandler> implements ISubscribable<TEventHandler> {
private _subscribe;
private _unsubscribe;
private _one;
private _has;
private _clear;
private _count;
private _onSubscriptionChange;
/**
* Creates an instance of DispatcherWrapper.
* @param {ISubscribable<TEventHandler>} dispatcher
*
* @memberOf DispatcherWrapper
*/
constructor(dispatcher: ISubscribable<TEventHandler>);
/**
* Triggered when subscriptions are changed (added or removed).
*
* @readonly
* @type {ISubscribable<SubscriptionChangeEventHandler>}
* @memberOf DispatcherWrapper
*/
get onSubscriptionChange(): ISubscribable<SubscriptionChangeEventHandler>;
/**
* Returns the number of subscriptions.
*
* @readonly
* @type {number}
* @memberOf DispatcherWrapper
*/
get count(): number;
/**
* Subscribe to the event dispatcher.
*
* @param {TEventHandler} fn The event handler that is called when the event is dispatched.
* @returns {() => void} A function that unsubscribes the event handler from the event.
*
* @memberOf DispatcherWrapper
*/
subscribe(fn: TEventHandler): () => void;
/**
* Subscribe to the event dispatcher.
*
* @param {TEventHandler} fn The event handler that is called when the event is dispatched.
* @returns {() => void} A function that unsubscribes the event handler from the event.
*
* @memberOf DispatcherWrapper
*/
sub(fn: TEventHandler): () => void;
/**
* Unsubscribe from the event dispatcher.
*
* @param {TEventHandler} fn The event handler that is called when the event is dispatched.
*
* @memberOf DispatcherWrapper
*/
unsubscribe(fn: TEventHandler): void;
/**
* Unsubscribe from the event dispatcher.
*
* @param {TEventHandler} fn The event handler that is called when the event is dispatched.
*
* @memberOf DispatcherWrapper
*/
unsub(fn: TEventHandler): void;
/**
* Subscribe once to the event with the specified name.
*
* @returns {() => void} A function that unsubscribes the event handler from the event.
*
* @memberOf DispatcherWrapper
*/
one(fn: TEventHandler): () => void;
/**
* Checks it the event has a subscription for the specified handler.
*
* @param {TEventHandler} fn The event handler that is called when the event is dispatched.
*
* @memberOf DispatcherWrapper
*/
has(fn: TEventHandler): boolean;
/**
* Clears all the subscriptions.
*
* @memberOf DispatcherWrapper
*/
clear(): void;
}