UNPKG

ts-bus

Version:

<p align="center"> <img src="logo.png" width="100" height="100"/> </p>

22 lines (21 loc) 968 B
import { EventBus, PredicateFn } from "./EventBus"; export declare type BusEvent<T extends object = any> = { type: string; payload: T; meta?: any; }; export declare type EventTypeDescriptor<T extends { type: string; }> = { eventType: T["type"]; }; export declare type EventFrom<T extends (...args: any) => BusEvent> = ReturnType<T>; export declare type DispatchFn<E> = (a: E) => void; export declare type UnsubscribeFn = () => any; export declare type SubscribeFn<E extends BusEvent> = (dispatch: DispatchFn<E>, bus: EventBus) => UnsubscribeFn; export declare type SubscriptionDef<T extends BusEvent> = string | EventCreatorFn<T> | PredicateFn<T> | T["type"]; export declare type SubscribeWithPayloadDispatchFn<E extends BusEvent> = (dispatch: DispatchFn<E["payload"]>, bus: EventBus) => UnsubscribeFn; export declare type EventCreatorFn<T extends { type: string; payload: any; }> = ((payload: T["payload"]) => T) & EventTypeDescriptor<T>;