networking
Version:
Library for typed, event-based networking between a server and clients.
12 lines (11 loc) • 988 B
TypeScript
import { Json } from '../serialize';
import { Emitter } from './emitter';
import { Schematic, Group, Key } from '../schema/schematic';
export declare class TransactionEmitter<T extends Schematic, I extends Group, O extends Group> extends Emitter<T> {
emit<E extends Events<O>>(event: E, ...args: Params<O, E>): void;
on<E extends Events<I>>(event: E, callback: Callback<I, E>): void;
once<E extends Events<I>>(event: E, callback: Callback<I, E>): void;
}
export declare type Events<G extends Group> = Key<G['transactions']>;
export declare type Callback<G extends Group, K extends Events<G>> = G extends undefined ? (...args: Json[]) => void : (G['transactions'] extends undefined ? (...args: Json[]) => void : ((...args: Parameters<NonNullable<G['transactions']>[K]>) => void));
export declare type Params<G extends Group, K extends Events<G>> = G extends undefined ? Json[] : (G['transactions'] extends undefined ? Json[] : (Parameters<NonNullable<G['transactions']>[K]>));