UNPKG

react-torch

Version:

A lib to server-side render with react.

46 lines (45 loc) 2.19 kB
import { Store, PreloadedState } from 'redux'; export type { Store, PreloadedState }; export declare type ReducerWithoutPayload<S = any> = (state: S) => S; export declare type ReducerWithPayload<S = any, P = any> = (state: S, payload: P) => S; export declare type ReducerWithOptionalPayload<S = any, P = any> = (state: S, payload?: P) => S; export declare type Reducer<S = any> = ReducerWithPayload<S> | ReducerWithoutPayload<S> | ReducerWithOptionalPayload<S>; export declare type Reducers<S = any> = { [key: string]: Reducer<S>; }; export declare type Tail<T extends any[]> = ((...t: T) => any) extends (_: any, ...tail: infer TT) => any ? TT : []; export declare type ReducerToAction<R extends Reducer> = R extends (...args: infer Args) => any ? (...args: Tail<Args>) => void : never; export declare type ReducersToActions<RS extends Reducers> = { [key in keyof RS]: ReducerToAction<RS[key]>; }; export declare type CreateStoreOptions<S, RS extends Reducers<S>> = { name?: string; initialState: S; reducers: RS; devtools?: boolean; logger?: boolean; }; export declare type CreateInternalStoreOptions<S, RS extends Reducers> = CreateStoreOptions<S, RS> & { preloadedState?: PreloadedState<S>; }; export declare type ActionObject = { type: string; payload?: any; }; export declare const createStore: <S, RS extends Reducers<S>>(options: CreateInternalStoreOptions<S, RS>) => { store: Store<S, ActionObject>; actions: ReducersToActions<RS>; }; declare type Stores = { [key: string]: Store; }; declare type StoreStateType<T extends Store> = T extends Store<infer S> ? S : never; declare type CombinedState<T extends Stores> = { [key in keyof T]: StoreStateType<T[key]>; }; declare type CombinedStore<T extends Stores> = Store<CombinedState<T>>; export declare const setupStore: <S, RS extends Reducers<S>>(options: CreateStoreOptions<S, RS>) => { store: Store<S, ActionObject>; actions: ReducersToActions<RS>; }, setupStart: (callback: () => any) => void, setupFinish: (callback: () => any) => void, setupPreload: (callback: () => any) => void; export declare function combineStore<T extends Stores>(stores: T): CombinedStore<T>;