/** * 本文件中的内容用于状态机 * @author PAO */ import { Reducer } from 'react'; import * as Redux from 'redux'; import { Action, Store } from 'redux'; import { PromiseType } from './base'; /** * 通用Action配置 */ declare class CommonAction implements Action { type: any; props?: any; } /** * 基础Action */ export interface ActionFunc { (state: S, props: P): S; } /** * Reducer字典 */ export declare type ReducerMap = { [key: string]: Reducer>; }; /** * Action字典、列表 */ export declare type ActionArray = ActionFunc[]; export declare type ReducerDefineMap = { [key: string]: ActionArray; } | ActionArray; /** * 状态机 */ export declare class StateMachine { /** * 存储 */ store: Store; constructor(reducers: ReducerDefineMap, initState: TState); private createStore; /** * 获取当前状态 */ getState(): TState; /** * 分发动作 * @param store 存储器 * @param actionType 动作类型 * @param state 状态 */ dispatch

(actionType: ActionFunc, actionProps?: P): CommonAction>; /** * 事件订阅 * @param listener 监听器 */ subscribe(listener: () => void): Redux.Unsubscribe; } /** * 创建动作 * @param actionType 动作类型 * @param actionProps 动作参数 */ export declare function createAction(actionType: ActionFunc, actionProps: P): CommonAction>; /** * 创建Reducer * @param reducer reducer类型 * @param initState 初始化状态 */ export declare function createStateMachine(reducers: ReducerDefineMap, initState: any): StateMachine; /** * 使用Reducer */ export declare function useStateMachine(stateMachine: StateMachine, onStateChanged?: (state: TState) => void, preJudgeState?: (state: TState) => boolean): [TState, (action: ActionFunc, actionProps: any) => void]; /** -----------异步Redux----------- */ /** 异步状态 */ export declare enum AsyncStatus { error = "\u6267\u884C\u9519\u8BEF", success = "\u8C03\u7528\u5B8C\u6210", running = "\u8FD0\u884C\u4E2D", notstart = "\u5C1A\u672A\u5F00\u59CB" } /** 异步调用State */ export interface AsyncState { status?: AsyncStatus; error?: string; lastStartTime?: Date; /** 上次完成时间 */ lastEndTime?: Date; } export interface AsyncCallState extends AsyncState { result?: TResult; } export interface StartCallProps { store: Store; asyncFunc: AsyncFunc; params: any[]; } export declare type AsyncFunc = (...params: any[]) => PromiseType; /** * 异步调用状态机 */ export declare class AsyncCallStateMachine extends StateMachine> { asyncFunc: AsyncFunc; constructor(asyncFunc: AsyncFunc, initResult: TResult); static StartCall(state: AsyncCallState, props: StartCallProps): { lastStartTime: Date; lastEndTime: undefined; status: AsyncStatus; promise: any; result?: any; error?: string | undefined; }; static SucessCall(state: AsyncCallState, result?: TResult): { lastEndTime: Date; status: AsyncStatus; result: TResult | undefined; error?: string | undefined; lastStartTime?: Date | undefined; }; static RejectCall(state: AsyncCallState, error?: string): { lastEndTime: Date; status: AsyncStatus; error: string | undefined; result?: any; lastStartTime?: Date | undefined; }; startAsyncCall(...params: any[]): void; setSuccess(result?: TResult): void; setError(error?: string): void; syncCall(): void; } /** * 创建异步调用状态机 * @param reducer reducer类型 * @param initState 初始化状态 */ export declare function createAsyncCallStateMachine(asyncFunc: AsyncFunc, initResult: TResult): AsyncCallStateMachine; /** * Hook模式的异步调用(适用于组件内部调用) * state是AsyncCallState类型的 */ export declare function useAsyncCall(initResult: TResult): [AsyncCallState, (asyncFunc: AsyncFunc, ...params: any[]) => void]; /** * 简单状态机 */ export declare class SimpleStateMachine extends StateMachine { static SetState: (state: any, newState: any) => any; constructor(initState: TState); refresh(): void; setState(value: TState): void; createChangeEventHandle(propName?: string, onChange?: (value: any) => void): (e: any) => void; } export {};