@snipsonian/observable-state
Version:
Observable-state snippets (redux-like)
43 lines (42 loc) • 1.95 kB
TypeScript
import { IGetState, ISetState, IObservableStateStore, IObservableStateStoreConfig } from '../store/types';
export interface Action<T = any> {
type: T;
}
export interface AnyAction extends Action {
[extraProps: string]: any;
}
export interface Dispatch<A extends Action = AnyAction> {
<T extends A>(action: T): T;
}
export interface Middleware<State = any, D extends Dispatch = Dispatch> {
(api: MiddlewareAPI<D, State>): (next: Dispatch<AnyAction>) => (action: any) => any;
}
export interface MiddlewareAPI<D extends Dispatch = Dispatch, State = any> {
dispatch: D;
getState(): State;
}
export interface IPayloadAction<Type, Payload> extends Action<Type> {
payload: Payload;
}
export interface IObservableStateAction<Type, Payload, State, ExtraProcessInput, StateChangeNotificationKey> extends IPayloadAction<Type, Payload> {
filter?: TFilterHook<State, this>;
process?: TProcessHook<State, this, ExtraProcessInput, StateChangeNotificationKey>;
}
export declare type TProcessHook<State, IncomingAction, ExtraProcessInput, StateChangeNotificationKey> = (input: {
action: IncomingAction;
getState: IGetState<State>;
setState: ISetState<State, StateChangeNotificationKey>;
dispatch: Dispatch<Action>;
} & ExtraProcessInput) => void | Promise<void>;
export declare type TFilterHook<State, IncomingAction> = (input: {
action: IncomingAction;
getState: IGetState<State>;
}) => TFilterHookResult<IncomingAction>;
export declare type TFilterHookResult<IncomingAction> = IncomingAction | false;
export interface IActionableObservableStateStore<State, StateChangeNotificationKey> extends IObservableStateStore<State, StateChangeNotificationKey> {
dispatch: Dispatch<Action>;
}
export interface IActionableObservableStateStoreConfig<State, ExtraProcessInput> extends IObservableStateStoreConfig<State> {
middlewares: Middleware[];
observableStateActionExtraProcessInput?: ExtraProcessInput;
}