mini-signals
Version:
signals, in TypeScript, fast
49 lines (48 loc) • 1.25 kB
TypeScript
type CallBack<T extends any[]> = (...x: T) => void;
declare const MINI_SIGNAL_KEY: unique symbol;
type MiniSignalNodeRef<T, S> = {
[MINI_SIGNAL_KEY]: Symbol;
} & {
__brand: S;
} & {
__type: T;
};
type MiniSignalNode<T extends any[]> = {
fn: CallBack<T>;
next?: MiniSignalNode<T>;
prev?: MiniSignalNode<T>;
};
export declare class MiniSignal<T extends any[] = any[], S extends any = Symbol | string> {
/**
* A Symbol that is used to guarantee the uniqueness of the MiniSignal
* instance.
*/
private readonly _symbol;
private _refMap;
private _head?;
private _tail?;
private _dispatching;
hasListeners(): boolean;
/**
* Dispatches a signal to all registered listeners.
*/
dispatch(...args: T): boolean;
/**
* Register a new listener.
*/
add(fn: CallBack<T>): MiniSignalNodeRef<T, S>;
/**
* Remove binding object.
*/
detach(sym: MiniSignalNodeRef<T, S>): this;
/**
* Detach all listeners.
*/
detachAll(): this;
private _destroyNode;
private _disconnectNode;
private _addNode;
private _createRef;
protected _getRef(sym: MiniSignalNodeRef<T, S>): MiniSignalNode<T> | undefined;
}
export {};