hbus
Version:
An event bus lib.
30 lines (29 loc) • 1.23 kB
TypeScript
import { Action } from "./Action";
import { Processor } from "./Processor";
import { Comparer } from "./Comparer";
export declare type Subscriber<S = any> = (state: S) => void;
export declare type StateRequestCallback<S = any> = (state: S) => void;
export declare class Bus<S = any, T = any, P = any> {
processor: Processor<S, Action<T, P>>;
constructor(processor: Processor<S, Action<T, P>>, defaultState?: S);
comparer: Comparer;
private _state;
private _stateRequestCallbacks;
private _willUpdate;
private _actions;
private _subscriberMap;
private _subscribers;
private _requestUdpate;
private _update;
getState(): S;
requestState(callback: StateRequestCallback<S>): this;
publish(action: Action<T, P>): this;
subscribe(subscriber: Subscriber<S>): this;
unsubscribe(subscriber: Subscriber<S>): this;
clearSubscribers(): this;
subscribeProp<P extends keyof S>(propName: P, subscriber: Subscriber<S[P]>): this;
unsubscribeProp<P extends keyof S>(propName: P, subscriber: Subscriber<S[P]>): this;
clearPropSubscribers(propName: keyof S): this;
clearAllPropSubscribers(): this;
clearAllSubscribers(): this;
}