29 lines
755 B
TypeScript
29 lines
755 B
TypeScript
import { ActionGenerator } from "./actions.js";
|
|
|
|
/**
|
|
* Configuration object typically passed to the constructor of the class Updux.
|
|
*/
|
|
export interface UpduxConfig<TState = any,TActions extends Record<string,ActionGenerator> = Record<string,ActionGenerator>, TSubduxes = {}> {
|
|
/**
|
|
* Local initial state.
|
|
* @default {}
|
|
*/
|
|
initial?: TState;
|
|
|
|
actions?: TActions;
|
|
|
|
/**
|
|
* Subduxes to be merged to this dux.
|
|
*/
|
|
subduxes?: TSubduxes;
|
|
}
|
|
|
|
type StateOf<D> = D extends { initial: infer I } ? I : unknown;
|
|
|
|
export type DuxStateSubduxes<C extends {}> = keyof C extends never
|
|
? unknown
|
|
: { [K in keyof C]: StateOf<C[K]> };
|
|
|
|
export type DuxAggregateState<TState,TSubduxes> = TState & DuxStateSubduxes<TSubduxes> ;
|
|
|