UNPKG

monarc

Version:

MONARC's Obviously Not A Redux Clone

99 lines (90 loc) 3.66 kB
/// <reference types="react" /> import * as react from 'react'; import { ComponentType, Context, FunctionComponent } from 'react'; declare type PluginState = { [k: string]: unknown; }; interface Action { type: string; [k: string]: any; } declare type ReducerProvider<S, A extends Action> = { Provider: ComponentType; reducer: Reducer<S, A>; ps?: PluginState; }; declare type Dispatch<A extends Action> = (action: A | Promise<A>) => void; declare type Reducer<S, A extends Action> = (state: S, action: A) => S; declare type AnyReducer<S, A extends Action> = ReducerProvider<S, A> | Array<Reducer<S, A>> | Reducer<S, A>; declare type EmptyDispatcher<A extends Action> = { dispatch: Dispatch<A> | null; }; declare type Dispatcher<A extends Action> = { dispatch: Dispatch<A>; }; declare type WrapReducer<S, O, A extends Action> = (reducer: Reducer<S, A>, ps: Partial<PluginState>, options: O) => Reducer<S, A>; declare type UseValue<O> = (ps: Partial<PluginState>, options: O) => unknown; declare type WithPlugin<S, O, A extends Action> = (anyReducer: AnyReducer<S, A>, options?: Partial<O>) => ReducerProvider<S, A>; declare type UsePlugin<C> = () => C; declare function createPlugin<S, O, A extends Action>(wrapReducer: WrapReducer<S, O, A>, defaults?: Partial<O>): [ WithPlugin<S, O, A> ]; declare function createPlugin<S, O, C, A extends Action>(wrapReducer: WrapReducer<S, O, A>, useValue: UseValue<O>, defaults?: Partial<O>): [ WithPlugin<S, O, A>, UsePlugin<C>, Context<C> ]; declare type Container<S> = FunctionComponent<{ initialState: S; children?: unknown; }>; declare function createContainer<S, A extends Action>(Component: ComponentType<{ store: S; }>, anyReducer: AnyReducer<S, A>, dispatcher?: EmptyDispatcher<A>): Container<S>; declare type UndoOpts = { setState: (previous: any, current: any) => any; getState: (state: any) => any; undoAction: string; redoAction: string; maxUndo: number; }; declare type UndoState = { prev: string | null; undo: Array<any>; redo: Array<any>; }; declare type UndoCtx = { canUndo: boolean; canRedo: boolean; }; declare const withUndoRedo: WithPlugin<any, UndoOpts, Action>; declare const useUndoRedo: UsePlugin<UndoCtx>; declare const undoContext: Context<UndoCtx>; declare type SaveFn = (state: any, callback?: () => void) => void; declare type UpdateFn = (previous: any, updated: any, action: Action, isTimerActive?: boolean) => boolean; declare type SaveOpts = { onBeforeUpdate?: UpdateFn; onUpdate: UpdateFn; onSave: SaveFn; delay: number; }; declare type SaveCtx = { isSaved: boolean; }; declare const withAutoSave: WithPlugin<any, SaveOpts, Action>; declare const useAutoSave: UsePlugin<SaveCtx>; declare const saveContext: Context<SaveCtx>; declare global { interface Window { __REDUX_DEVTOOLS_EXTENSION__?: any; } } declare const withDevTools: WithPlugin<any, unknown, Action>; declare type StoreContext<S, A extends Action> = { dispatch: Dispatch<A>; state: S; }; declare const storeContext: react.Context<StoreContext<any, any>>; declare function useDispatch<A extends Action>(): Dispatch<A>; declare function useStore<S, A extends Action>(): S; export { Action, AnyReducer, Dispatch, Dispatcher, EmptyDispatcher, PluginState, Reducer, ReducerProvider, UndoState, UsePlugin, UseValue, WithPlugin, WrapReducer, createContainer, createPlugin, saveContext, storeContext, undoContext, useAutoSave, useDispatch, useStore, useUndoRedo, withAutoSave, withDevTools, withUndoRedo };