UNPKG

3.51 kBTypeScriptView Raw
1import type { Reducer, ReducersMapObject, Middleware, Action, AnyAction, StoreEnhancer, Store, Dispatch, PreloadedState, CombinedState } from 'redux';
2import type { EnhancerOptions as DevToolsOptions } from './devtoolsExtension';
3import type { ThunkMiddlewareFor, CurriedGetDefaultMiddleware } from './getDefaultMiddleware';
4import type { DispatchForMiddlewares, NoInfer } from './tsHelpers';
5/**
6 * Callback function type, to be used in `ConfigureStoreOptions.enhancers`
7 *
8 * @public
9 */
10export declare type ConfigureEnhancersCallback = (defaultEnhancers: readonly StoreEnhancer[]) => StoreEnhancer[];
11/**
12 * Options for `configureStore()`.
13 *
14 * @public
15 */
16export interface ConfigureStoreOptions<S = any, A extends Action = AnyAction, M extends Middlewares<S> = Middlewares<S>> {
17 /**
18 * A single reducer function that will be used as the root reducer, or an
19 * object of slice reducers that will be passed to `combineReducers()`.
20 */
21 reducer: Reducer<S, A> | ReducersMapObject<S, A>;
22 /**
23 * An array of Redux middleware to install. If not supplied, defaults to
24 * the set of middleware returned by `getDefaultMiddleware()`.
25 */
26 middleware?: ((getDefaultMiddleware: CurriedGetDefaultMiddleware<S>) => M) | M;
27 /**
28 * Whether to enable Redux DevTools integration. Defaults to `true`.
29 *
30 * Additional configuration can be done by passing Redux DevTools options
31 */
32 devTools?: boolean | DevToolsOptions;
33 /**
34 * The initial state, same as Redux's createStore.
35 * You may optionally specify it to hydrate the state
36 * from the server in universal apps, or to restore a previously serialized
37 * user session. If you use `combineReducers()` to produce the root reducer
38 * function (either directly or indirectly by passing an object as `reducer`),
39 * this must be an object with the same shape as the reducer map keys.
40 */
41 preloadedState?: PreloadedState<CombinedState<NoInfer<S>>>;
42 /**
43 * The store enhancers to apply. See Redux's `createStore()`.
44 * All enhancers will be included before the DevTools Extension enhancer.
45 * If you need to customize the order of enhancers, supply a callback
46 * function that will receive the original array (ie, `[applyMiddleware]`),
47 * and should return a new array (such as `[applyMiddleware, offline]`).
48 * If you only need to add middleware, you can use the `middleware` parameter instead.
49 */
50 enhancers?: StoreEnhancer[] | ConfigureEnhancersCallback;
51}
52declare type Middlewares<S> = ReadonlyArray<Middleware<{}, S>>;
53/**
54 * A Redux store returned by `configureStore()`. Supports dispatching
55 * side-effectful _thunks_ in addition to plain actions.
56 *
57 * @public
58 */
59export interface EnhancedStore<S = any, A extends Action = AnyAction, M extends Middlewares<S> = Middlewares<S>> extends Store<S, A> {
60 /**
61 * The `dispatch` method of your store, enhanced by all its middlewares.
62 *
63 * @inheritdoc
64 */
65 dispatch: DispatchForMiddlewares<M> & Dispatch<A>;
66}
67/**
68 * A friendly abstraction over the standard Redux `createStore()` function.
69 *
70 * @param config The store configuration.
71 * @returns A configured Redux store.
72 *
73 * @public
74 */
75export declare function configureStore<S = any, A extends Action = AnyAction, M extends Middlewares<S> = [ThunkMiddlewareFor<S>]>(options: ConfigureStoreOptions<S, A, M>): EnhancedStore<S, A, M>;
76export {};
77
\No newline at end of file