import type { Action } from "redux"; import type { Reducer } from "../reducers"; import type { ObservableStore } from "../store/ObservableStore"; import type { State, StateConstructor, StateKey } from "../reducers"; import type { Dispatch } from "redux"; export declare type GetStoreState = () => S; export declare type DispatchState = any> = Dispatch; export declare type ActionFactoryDecorator = (factoryCtor: ActionFactoryConstructor) => T; export declare type ActionFn = (...args: Args) => any; export interface ActionRegistration = ActionFactory, Fn extends ActionFn = ActionFn> { type: string; fullName: string; leaf: string | F["leaf"]; action: Fn; options: ActionOptions>; actionFactoryCtor: ActionFactoryConstructor; } export declare type ActionOptions = ActionFactoryConstructor> = { isPromise?: boolean; isReducer?: boolean; factoryCtor?: A; reducers?: Reducer[]; mapped?: string[]; }; /** * Action factory provider */ export declare type ActionFnProvider = (...args: any[]) => (dispatch: any, getState: any) => T; /** * Action reducer provider */ export declare type ActionReducerProvider = (...args: any[]) => (state: S) => S; /** * Action provider */ export declare type ActionProvider = ActionFnProvider | ActionReducerProvider; export interface ActionFactory = ActionMessage, K extends StateKey = StateKey> { /** * Currently assigned store, fallback to global * if set */ readonly getStore: () => ObservableStore; /** * Get the state constructor */ readonly stateType: StateConstructor; /** * Get the leaf key */ readonly leaf: () => string | K; /** * Get all currently registered actions */ readonly actions: ActionRegistration[]; /** * Get action by name * * @param fullName - full name or type */ getAction(fullName: string): any; /** * Get action by parts * * @param leaf * @param type */ getAction(leaf: string, type: string): any; readonly dispatcher: Dispatch>; readonly state: S; /** * Register an action. Registrations * are used for store binding and * message generation, should not be * used directly * * @param reg */ readonly registerAction: (reg: ActionRegistration) => ActionRegistration; readonly withStore: (newStore: ObservableStore) => this; readonly setStore: (newStore: ObservableStore) => this; readonly newMessage: (id: string, leaf: string, type: string, reducers?: Reducer>[], args?: any[], data?: any) => M; } export interface ActionFactoryConstructor, S extends Clazz["state"] = Clazz["state"]> { setStore: (store: ObservableStore) => void; new (store?: ObservableStore): Clazz; } export interface ActionMessage extends Action { id?: string; leaf?: string | S["type"]; type: string; stateType: StateConstructor; args?: any[]; reducers?: Reducer>[]; error?: Error; } export declare enum ActionStatus { Started = 1, Finished = 2 } export interface PendingAction { id: string; leaf: string; name: string; status: ActionStatus; }