UNPKG

yavent

Version:

A flexible, lightweight event subscriber & emitter

15 lines (14 loc) 763 B
export declare type Callback<T> = (payload: T) => void; export declare type Unsubscribe = () => void; export declare type OnEvent<T> = (callback: Callback<T>) => Unsubscribe; export declare type EmitEvent<T> = (payload: T) => void; export declare type Event<T> = [OnEvent<T>, EmitEvent<T>]; export declare type OnEvents<T> = <Name extends keyof T>(name: Name, callback: Callback<T[Name]>) => Unsubscribe; export declare type EmitEvents<T> = <Name extends keyof T>(name: Name, payload: T[Name]) => void; export declare type Events<T> = [OnEvents<T>, EmitEvents<T>]; /** * Create a standalone event. * Returns a subscriber function and an emitter function. */ export declare function makeEvent<T>(): Event<T>; export declare function makeEvents<T>(): Events<T>;