123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676 |
- export interface Action<T = any> {
- type: T
- }
- export interface AnyAction extends Action {
-
- [extraProps: string]: any
- }
- declare const $CombinedState: unique symbol
- interface EmptyObject {
- readonly [$CombinedState]?: undefined
- }
- export type CombinedState<S> = EmptyObject & S
- export type PreloadedState<S> = Required<S> extends EmptyObject
- ? S extends CombinedState<infer S1>
- ? {
- [K in keyof S1]?: S1[K] extends object ? PreloadedState<S1[K]> : S1[K]
- }
- : S
- : {
- [K in keyof S]: S[K] extends string | number | boolean | symbol
- ? S[K]
- : PreloadedState<S[K]>
- }
- export type Reducer<S = any, A extends Action = AnyAction> = (
- state: S | undefined,
- action: A
- ) => S
- export type ReducersMapObject<S = any, A extends Action = Action> = {
- [K in keyof S]: Reducer<S[K], A>
- }
- export type StateFromReducersMapObject<M> = M extends ReducersMapObject<
- any,
- any
- >
- ? { [P in keyof M]: M[P] extends Reducer<infer S, any> ? S : never }
- : never
- export type ReducerFromReducersMapObject<M> = M extends {
- [P in keyof M]: infer R
- }
- ? R extends Reducer<any, any>
- ? R
- : never
- : never
- export type ActionFromReducer<R> = R extends Reducer<any, infer A> ? A : never
- export type ActionFromReducersMapObject<M> = M extends ReducersMapObject<
- any,
- any
- >
- ? ActionFromReducer<ReducerFromReducersMapObject<M>>
- : never
- export function combineReducers<S>(
- reducers: ReducersMapObject<S, any>
- ): Reducer<CombinedState<S>>
- export function combineReducers<S, A extends Action = AnyAction>(
- reducers: ReducersMapObject<S, A>
- ): Reducer<CombinedState<S>, A>
- export function combineReducers<M extends ReducersMapObject<any, any>>(
- reducers: M
- ): Reducer<
- CombinedState<StateFromReducersMapObject<M>>,
- ActionFromReducersMapObject<M>
- >
- /* store */
- /**
- * A *dispatching function* (or simply *dispatch function*) is a function that
- * accepts an action or an async action; it then may or may not dispatch one
- * or more actions to the store.
- *
- * We must distinguish between dispatching functions in general and the base
- * `dispatch` function provided by the store instance without any middleware.
- *
- * The base dispatch function *always* synchronously sends an action to the
- * store's reducer, along with the previous state returned by the store, to
- * calculate a new state. It expects actions to be plain objects ready to be
- * consumed by the reducer.
- *
- * Middleware wraps the base dispatch function. It allows the dispatch
- * function to handle async actions in addition to actions. Middleware may
- * transform, delay, ignore, or otherwise interpret actions or async actions
- * before passing them to the next middleware.
- *
- * @template A The type of things (actions or otherwise) which may be
- * dispatched.
- */
- export interface Dispatch<A extends Action = AnyAction> {
- <T extends A>(action: T): T
- }
- /**
- * Function to remove listener added by `Store.subscribe()`.
- */
- export interface Unsubscribe {
- (): void
- }
- declare global {
- interface SymbolConstructor {
- readonly observable: symbol
- }
- }
- /**
- * A minimal observable of state changes.
- * For more information, see the observable proposal:
- * https://github.com/tc39/proposal-observable
- */
- export type Observable<T> = {
- /**
- * The minimal observable subscription method.
- * @param {Object} observer Any object that can be used as an observer.
- * The observer object should have a `next` method.
- * @returns {subscription} An object with an `unsubscribe` method that can
- * be used to unsubscribe the observable from the store, and prevent further
- * emission of values from the observable.
- */
- subscribe: (observer: Observer<T>) => { unsubscribe: Unsubscribe }
- [Symbol.observable](): Observable<T>
- }
- /**
- * An Observer is used to receive data from an Observable, and is supplied as
- * an argument to subscribe.
- */
- export type Observer<T> = {
- next?(value: T): void
- }
- export interface Store<S = any, A extends Action = AnyAction> {
-
- dispatch: Dispatch<A>
-
- getState(): S
-
- subscribe(listener: () => void): Unsubscribe
-
- replaceReducer(nextReducer: Reducer<S, A>): void
-
- [Symbol.observable](): Observable<S>
- }
- export type DeepPartial<T> = {
- [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]
- }
- export interface StoreCreator {
- <S, A extends Action, Ext, StateExt>(
- reducer: Reducer<S, A>,
- enhancer?: StoreEnhancer<Ext, StateExt>
- ): Store<S & StateExt, A> & Ext
- <S, A extends Action, Ext, StateExt>(
- reducer: Reducer<S, A>,
- preloadedState?: PreloadedState<S>,
- enhancer?: StoreEnhancer<Ext>
- ): Store<S & StateExt, A> & Ext
- }
- export const createStore: StoreCreator
- export type StoreEnhancer<Ext = {}, StateExt = {}> = (
- next: StoreEnhancerStoreCreator
- ) => StoreEnhancerStoreCreator<Ext, StateExt>
- export type StoreEnhancerStoreCreator<Ext = {}, StateExt = {}> = <
- S = any,
- A extends Action = AnyAction
- >(
- reducer: Reducer<S, A>,
- preloadedState?: PreloadedState<S>
- ) => Store<S & StateExt, A> & Ext
- export interface MiddlewareAPI<D extends Dispatch = Dispatch, S = any> {
- dispatch: D
- getState(): S
- }
- export interface Middleware<
- DispatchExt = {},
- S = any,
- D extends Dispatch = Dispatch
- > {
- (api: MiddlewareAPI<D, S>): (
- next: Dispatch<AnyAction>
- ) => (action: any) => any
- }
- export function applyMiddleware(): StoreEnhancer
- export function applyMiddleware<Ext1, S>(
- middleware1: Middleware<Ext1, S, any>
- ): StoreEnhancer<{ dispatch: Ext1 }>
- export function applyMiddleware<Ext1, Ext2, S>(
- middleware1: Middleware<Ext1, S, any>,
- middleware2: Middleware<Ext2, S, any>
- ): StoreEnhancer<{ dispatch: Ext1 & Ext2 }>
- export function applyMiddleware<Ext1, Ext2, Ext3, S>(
- middleware1: Middleware<Ext1, S, any>,
- middleware2: Middleware<Ext2, S, any>,
- middleware3: Middleware<Ext3, S, any>
- ): StoreEnhancer<{ dispatch: Ext1 & Ext2 & Ext3 }>
- export function applyMiddleware<Ext1, Ext2, Ext3, Ext4, S>(
- middleware1: Middleware<Ext1, S, any>,
- middleware2: Middleware<Ext2, S, any>,
- middleware3: Middleware<Ext3, S, any>,
- middleware4: Middleware<Ext4, S, any>
- ): StoreEnhancer<{ dispatch: Ext1 & Ext2 & Ext3 & Ext4 }>
- export function applyMiddleware<Ext1, Ext2, Ext3, Ext4, Ext5, S>(
- middleware1: Middleware<Ext1, S, any>,
- middleware2: Middleware<Ext2, S, any>,
- middleware3: Middleware<Ext3, S, any>,
- middleware4: Middleware<Ext4, S, any>,
- middleware5: Middleware<Ext5, S, any>
- ): StoreEnhancer<{ dispatch: Ext1 & Ext2 & Ext3 & Ext4 & Ext5 }>
- export function applyMiddleware<Ext, S = any>(
- ...middlewares: Middleware<any, S, any>[]
- ): StoreEnhancer<{ dispatch: Ext }>
- /* action creators */
- /**
- * An *action creator* is, quite simply, a function that creates an action. Do
- * not confuse the two terms—again, an action is a payload of information, and
- * an action creator is a factory that creates an action.
- *
- * Calling an action creator only produces an action, but does not dispatch
- * it. You need to call the store's `dispatch` function to actually cause the
- * mutation. Sometimes we say *bound action creators* to mean functions that
- * call an action creator and immediately dispatch its result to a specific
- * store instance.
- *
- * If an action creator needs to read the current state, perform an API call,
- * or cause a side effect, like a routing transition, it should return an
- * async action instead of an action.
- *
- * @template A Returned action type.
- */
- export interface ActionCreator<A> {
- (...args: any[]): A
- }
- /**
- * Object whose values are action creator functions.
- */
- export interface ActionCreatorsMapObject<A = any> {
- [key: string]: ActionCreator<A>
- }
- /**
- * Turns an object whose values are action creators, into an object with the
- * same keys, but with every function wrapped into a `dispatch` call so they
- * may be invoked directly. This is just a convenience method, as you can call
- * `store.dispatch(MyActionCreators.doSomething())` yourself just fine.
- *
- * For convenience, you can also pass a single function as the first argument,
- * and get a function in return.
- *
- * @param actionCreator An object whose values are action creator functions.
- * One handy way to obtain it is to use ES6 `import * as` syntax. You may
- * also pass a single function.
- *
- * @param dispatch The `dispatch` function available on your Redux store.
- *
- * @returns The object mimicking the original object, but with every action
- * creator wrapped into the `dispatch` call. If you passed a function as
- * `actionCreator`, the return value will also be a single function.
- */
- export function bindActionCreators<A, C extends ActionCreator<A>>(
- actionCreator: C,
- dispatch: Dispatch
- ): C
- export function bindActionCreators<
- A extends ActionCreator<any>,
- B extends ActionCreator<any>
- >(actionCreator: A, dispatch: Dispatch): B
- export function bindActionCreators<A, M extends ActionCreatorsMapObject<A>>(
- actionCreators: M,
- dispatch: Dispatch
- ): M
- export function bindActionCreators<
- M extends ActionCreatorsMapObject<any>,
- N extends ActionCreatorsMapObject<any>
- >(actionCreators: M, dispatch: Dispatch): N
- /* compose */
- type Func0<R> = () => R
- type Func1<T1, R> = (a1: T1) => R
- type Func2<T1, T2, R> = (a1: T1, a2: T2) => R
- type Func3<T1, T2, T3, R> = (a1: T1, a2: T2, a3: T3, ...args: any[]) => R
- /**
- * Composes single-argument functions from right to left. The rightmost
- * function can take multiple arguments as it provides the signature for the
- * resulting composite function.
- *
- * @param funcs The functions to compose.
- * @returns R function obtained by composing the argument functions from right
- * to left. For example, `compose(f, g, h)` is identical to doing
- * `(...args) => f(g(h(...args)))`.
- */
- export function compose(): <R>(a: R) => R
- export function compose<F extends Function>(f: F): F
- /* two functions */
- export function compose<A, R>(f1: (b: A) => R, f2: Func0<A>): Func0<R>
- export function compose<A, T1, R>(
- f1: (b: A) => R,
- f2: Func1<T1, A>
- ): Func1<T1, R>
- export function compose<A, T1, T2, R>(
- f1: (b: A) => R,
- f2: Func2<T1, T2, A>
- ): Func2<T1, T2, R>
- export function compose<A, T1, T2, T3, R>(
- f1: (b: A) => R,
- f2: Func3<T1, T2, T3, A>
- ): Func3<T1, T2, T3, R>
- /* three functions */
- export function compose<A, B, R>(
- f1: (b: B) => R,
- f2: (a: A) => B,
- f3: Func0<A>
- ): Func0<R>
- export function compose<A, B, T1, R>(
- f1: (b: B) => R,
- f2: (a: A) => B,
- f3: Func1<T1, A>
- ): Func1<T1, R>
- export function compose<A, B, T1, T2, R>(
- f1: (b: B) => R,
- f2: (a: A) => B,
- f3: Func2<T1, T2, A>
- ): Func2<T1, T2, R>
- export function compose<A, B, T1, T2, T3, R>(
- f1: (b: B) => R,
- f2: (a: A) => B,
- f3: Func3<T1, T2, T3, A>
- ): Func3<T1, T2, T3, R>
- /* four functions */
- export function compose<A, B, C, R>(
- f1: (b: C) => R,
- f2: (a: B) => C,
- f3: (a: A) => B,
- f4: Func0<A>
- ): Func0<R>
- export function compose<A, B, C, T1, R>(
- f1: (b: C) => R,
- f2: (a: B) => C,
- f3: (a: A) => B,
- f4: Func1<T1, A>
- ): Func1<T1, R>
- export function compose<A, B, C, T1, T2, R>(
- f1: (b: C) => R,
- f2: (a: B) => C,
- f3: (a: A) => B,
- f4: Func2<T1, T2, A>
- ): Func2<T1, T2, R>
- export function compose<A, B, C, T1, T2, T3, R>(
- f1: (b: C) => R,
- f2: (a: B) => C,
- f3: (a: A) => B,
- f4: Func3<T1, T2, T3, A>
- ): Func3<T1, T2, T3, R>
- /* rest */
- export function compose<R>(
- f1: (b: any) => R,
- ...funcs: Function[]
- ): (...args: any[]) => R
- export function compose<R>(...funcs: Function[]): (...args: any[]) => R
|