UNPKG

@typescript-tea/core

Version:

The Elm Architecture for typescript

48 lines 2.41 kB
/** @ignore */ /** */ /** * Commands and Subscriptions are both effects and they can both be batched and mapped. * This module handles the batching and mapping of both commands and subscriptions * in a generic way. * Each effect specifies a "home" that it belongs to. The effects can then be * gathered by "home" and passed to the Effect Manager for that "home". * This is an internal module which is not intended for outside usage. * Please use only the Cmd and Sub modules externally. */ export declare type Effect<A> = BatchedEffect<A> | MappedEffect<A, unknown> | LeafEffect<A>; export declare const InternalHome = "__internal"; export declare type InternalHome = typeof InternalHome; export declare type LeafEffect<_A, Home = string> = { readonly home: Home; readonly type: string; }; export declare type BatchedEffect<A> = { readonly home: InternalHome; readonly type: "Batched"; readonly list: ReadonlyArray<Effect<A>>; }; export declare type MappedEffect<A1, A2> = { readonly home: InternalHome; readonly type: "Mapped"; readonly actionMapper: (a1: A1) => A2; readonly original: BatchedEffect<A1> | MappedEffect<A1, A2> | LeafEffect<A1>; }; export declare function batchEffects<A>(effects: ReadonlyArray<Effect<A> | undefined>): BatchedEffect<A>; export declare function mapEffect<A1, A2>(actionMapper: (a1: A1) => A2, c: BatchedEffect<A1> | MappedEffect<A1, A2> | LeafEffect<A1> | undefined): MappedEffect<A1, A2> | undefined; export declare type LeafEffectMapper<A1 = unknown, A2 = unknown> = (actionMapper: (a1: A1) => A2, effect: Effect<A1>) => LeafEffect<A2>; export declare type GatheredEffects<A> = { [home: string]: { readonly cmds: Array<LeafEffect<A>>; readonly subs: Array<LeafEffect<A>>; }; }; export declare type EffectMapper<A1 = unknown, A2 = unknown, THome = unknown> = { readonly home: THome; readonly mapCmd: LeafEffectMapper<A1, A2>; readonly mapSub: LeafEffectMapper<A1, A2>; }; /** * This function is optimized for performance. Hence the ugly boolean * and the mutable input param. */ export declare function gatherEffects<A>(getEffectMapper: (home: string) => EffectMapper, gatheredEffects: GatheredEffects<A>, isCmd: boolean, effect: Effect<unknown>, actionMapper?: ((a1: unknown) => unknown) | undefined): void; //# sourceMappingURL=effect.d.ts.map