typedux
Version:
Slightly adjusted Redux (awesome by default) for TS
102 lines (101 loc) • 3.46 kB
TypeScript
import type { ObservableStore } from "../store/ObservableStore";
import type { State } from "../reducers";
import type { ActionFactory, ActionFactoryConstructor, ActionFn, ActionMessage, ActionOptions, ActionRegistration, DispatchState, GetStoreState } from "./ActionTypes";
import { InternalState } from "../internal/InternalState";
export interface ActionInterceptorNext {
(): any;
}
export interface ActionInterceptor {
(reg: ActionRegistration, next: ActionInterceptorNext, ...args: any[]): any;
}
/**
* Create a fully qualified action type
*
* @param leaf
* @param type
*
* @returns {string}
*/
export declare function createLeafActionType(leaf: string, type: string): string;
export declare function createActionRegistration<A extends ActionFactory, F extends ActionFactoryConstructor<A> = ActionFactoryConstructor<A>, K extends string | A["leaf"] = A["leaf"]>(actionFactoryCtor: F, leaf: string | K, type: string, action: ActionFn, options?: ActionOptions<F>): ActionRegistration;
export declare const getGlobalStore: () => ObservableStore<any>;
export declare const getGlobalStoreState: () => any;
/**
* Get the current store state get
* function - usually set when a new state is created
*
* @returns {GetStoreState}
*/
export declare function getGlobalStateProvider<S extends State = any>(): GetStoreState<S>;
/**
* Get the current store
* dispatch function
*
* @returns {DispatchState}
*/
export declare function getGlobalDispatchProvider(): DispatchState;
/**
* Get the stores internal state
*
* @returns {GetStoreState|any}
*/
export declare function getGlobalStoreInternalState(): InternalState;
/**
* Set the global store provider
*
* @param newStore
*/
export declare function setGlobalStore<Store extends ObservableStore>(newStore: Store): void;
export declare class ActionContainer {
store: ObservableStore<any>;
registeredActions: {
[actionType: string]: ActionRegistration;
};
actionInterceptors: ActionInterceptor[];
constructor(store: ObservableStore<any>);
/**
* Add an interceptor
*
* @param interceptor
* @returns {()=>undefined}
*/
addActionInterceptor(interceptor: ActionInterceptor): () => void;
/**
* Execute an interceptor at a specific index
*
* @param index
* @param reg
* @param actionId
* @param action
* @param args
* @returns {any}
*/
executeActionInterceptor(index: number, reg: ActionRegistration, actionId: string, action: Function, args: any[]): any;
/**
* Execute a given action chain
*
* @param reg
* @param actionFn
* @param args
* @returns {any|any}
*/
executeActionChain(reg: ActionRegistration, actionFn: Function, ...args: any[]): any;
/**
* Register an action from a decoration usually
*
* @param reg
* @return {ActionRegistration}
*/
registerAction<A extends ActionFactory, F extends ActionFactoryConstructor<A> = ActionFactoryConstructor<A>, K extends A["leaf"] = A["leaf"]>(reg: ActionRegistration): ActionRegistration;
/**
* Retrieve a registered leaf action
*
* @param leaf
* @param type
* @returns {ActionRegistration}
*/
getAction(leaf: string, type: string): ActionRegistration;
getAllActions(): {
[actionType: string]: ActionRegistration<State<any>, ActionFactory<State<any>, ActionMessage<State<any>>, any>, ActionFn<any>>;
};
}