// Type definitions for Rematch v0.4.0 // Project: Rematch // Definitions by: Shawn McKay https://github.com/shmck import { AnyAction, Dispatch, MiddlewareAPI, Middleware, ReducersMapObject, Store, StoreCreator, StoreEnhancer } from 'redux' export as namespace rematch export type RematchDispatch = { [key: string]: { [key:string]: (action: Action) => Promise> } } | ((action: Action) => Promise>) export let dispatch: RematchDispatch; export function init(config: Config | undefined): Store export function model(model: Model): void export function getState(): any export namespace rematch { export let dispatch: RematchDispatch; export function init(config: Config): Store export function model(model: Model): void export function getState(): any } export type Action = { type: string, payload?: any, meta?: any, } export type EnhancedReducer = (state: S, payload: object, meta: object) => S; export type EnhancedReducers = { [key: string]: EnhancedReducer, } export type Reducer = (state: S, payload?: any) => S; export type Reducers = { [key: string]: Reducer, } export type Models = { [key: string]: Model, } export type ModelHook = (model: Model) => void export type Validation = [boolean | undefined, string] export type Exposed = { dispatch: Dispatch | { [key: string]: () => void }, effects: any, createDispatcher: (modelName: string, reducerName: string) => any, validate: (validations: Validation[]) => void, [key: string]: any, } export interface Model { name?: string, state: any, reducers?: Reducers, effects?: { [key: string]: (payload: any, state: any) => void, }, selectors?: { [key: string]: (state: any, arg?: any) => any, }, subscriptions?: { [matcher: string]: (action: Action) => void, }, } export interface Plugin { onStoreCreated?: (store: Store) => void, onModel?: ModelHook, middleware?: (store: MiddlewareAPI) => (next: Dispatch) => (action: Action) => any, } export interface PluginCreator { config?: Config, expose?: { [key: string]: any, }, init?: (exposed: Exposed) => Plugin } export interface RootReducers { [type: string]: Reducer, } export interface ConfigRedux { initialState?: any, reducers?: Reducers, enhancers?: StoreEnhancer[], middlewares?: Middleware[], rootReducers?: RootReducers, combineReducers?: (reducers: ReducersMapObject) => Reducer, createStore?: StoreCreator, devtoolOptions?: Object, } export interface Config { models?: Models, plugins?: PluginCreator[], redux?: ConfigRedux, }