UNPKG

reactive-state

Version:

Redux-like state management using RxJS and TypeScript

25 lines (24 loc) 1.14 kB
import { Observer, Observable } from "rxjs"; import { ExtractProps } from "./connect"; export declare type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]; export declare type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>; export declare type UnaryFunction<T> = (t: T, ...args: any[]) => any; export declare type ActionFunction = (...args: any[]) => any; export declare type ActionMap<TComponentOrProps> = { [P in keyof FunctionProperties<ExtractProps<TComponentOrProps>>]?: ActionFunction | Observer<FunctionProperties<ExtractProps<TComponentOrProps>>[P] extends UnaryFunction<infer A> ? A : never>; }; /** * A map specifying which property on the components state should be populated with * the value of the map value (=Observable) * * @example * const map = { * secondsPassed: Observable.interval(1000) * } */ export declare type UnpackMap<TComponentState> = { [P in keyof TComponentState]?: Observable<TComponentState[P]>; }; export declare function assembleActionProps<TOriginalProps>(actionMap: ActionMap<TOriginalProps>): Partial<TOriginalProps>;