UNPKG

bgio-effects

Version:

📤 Helpers for managing state effects in boardgame.io

45 lines (44 loc) • 1.63 kB
/// <reference types="react" /> import type { O } from 'ts-toolbelt'; import type { BoardProps } from 'boardgame.io/react'; import type { BuiltinEffect, EffectsMap, EffectWithCreate, EffectPayload } from '../types'; /** * Interface provided by the `useEffectQueue` hook for manipulating * the current effect queue. */ export interface QueueAPI { clear: () => void; flush: () => void; update: () => void; size: number; } /** * Return type for all effect listener callbacks. */ declare type CbReturn = void | (() => void); /** * Type of callback when listening for all effects with '*'. */ declare type AllEffectsCb<E extends EffectsMap, G> = (...cbArgs: O.UnionOf<{ [K in keyof E]: E[K] extends EffectWithCreate ? [K, EffectPayload<E[K]>, BoardProps<G>] : [K, undefined, BoardProps<G>]; }>) => CbReturn; /** * Type of callback when listening for a specific effect. */ declare type EffectCb<E extends EffectsMap, K extends keyof E, G> = E[K] extends EffectWithCreate ? (payload: EffectPayload<E[K]>, context: BoardProps<G>) => CbReturn : (payload: undefined, context: BoardProps<G>) => CbReturn; export declare type ListenerArgs<E extends EffectsMap, G> = ['*', AllEffectsCb<E, G>, React.DependencyList] | [ '*', AllEffectsCb<E, G>, React.DependencyList, AllEffectsCb<E, G>, React.DependencyList ] | O.UnionOf<{ [K in keyof E]: [K, EffectCb<E, K, G>, React.DependencyList] | [ K, EffectCb<E, K, G>, React.DependencyList, EffectCb<E, K, G>, React.DependencyList ]; }> | [BuiltinEffect, () => CbReturn, React.DependencyList]; export {};