UNPKG

@gongt/ts-stl-client

Version:
45 lines (44 loc) 2.25 kB
import { GlobalVariable } from '@gongt/ts-stl-library/pattern/global-page-data'; import { compose, Dispatch, Middleware, Reducer, Store, Unsubscribe } from 'redux'; import { ArrayOrSingle } from '../global'; import { IAction, IAData } from './action'; import { IState } from './preload-state'; import { IVirtualStore, IVirtualStoreConstructor } from './virtual-store'; export declare type AppStore<StateInterface extends IState> = Store<StateInterface>; export declare type ReduxStoreType = ReduxStore<any>; export declare type LogicFunction<T> = (store: ReduxStore<T>) => void; export declare type BorderLogicFunction<T> = (subscribe: (listener: (state: T) => void) => Unsubscribe, dispatch: Dispatch<T>) => void; export declare type SimpleMiddleware<T, D extends IAData> = (store: AppStore<T>, action: IAction<D>) => void | IAction<D> | Promise<void | IAction<D>>; export declare const REDUX_PRELOAD_NAME = "__REDUX_PRELOAD_DATA__"; export interface MiddlewareCreator { (global: GlobalVariable): Middleware; } export interface IPlugin<State extends IState> { __redux_plugin(reduxStore: ReduxStore<State>): void; } /** * 根据逻辑函数(构造函数的参数)创建Store */ export declare class ReduxStore<StateInterface extends IState> { middlewares: Middleware[]; processObject: BorderLogicFunction<StateInterface>[]; subStore: { [id: string]: IVirtualStore<any>; }; protected readonly composeEnhancers: typeof compose; private finished; private middleware_callbacks; constructor(logicRegister?: ArrayOrSingle<LogicFunction<StateInterface>>); createStore(global: GlobalVariable): AppStore<StateInterface>; /** 添加预处理 */ logicDisplayBorder(middleware: BorderLogicFunction<StateInterface>): void; plugin(plugin: IPlugin<Partial<StateInterface>>): void; /** 添加子存储 */ register<T>(Constructor: IVirtualStoreConstructor<T>): void; /** 添加中间件 */ use(middleware: Middleware): void; useDynamic(callback: MiddlewareCreator): void; useSimple<D extends IAData>(middleware: SimpleMiddleware<StateInterface, D>): void; protected combineReducers(): Reducer<StateInterface>; protected getPreloadState(global: GlobalVariable): any; }