• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { Dispatch } from './store'
2
3export interface MiddlewareAPI<D extends Dispatch = Dispatch, S = any> {
4  dispatch: D
5  getState(): S
6}
7
8/**
9 * A middleware is a higher-order function that composes a dispatch function
10 * to return a new dispatch function. It often turns async actions into
11 * actions.
12 *
13 * Middleware is composable using function composition. It is useful for
14 * logging actions, performing side effects like routing, or turning an
15 * asynchronous API call into a series of synchronous actions.
16 *
17 * @template DispatchExt Extra Dispatch signature added by this middleware.
18 * @template S The type of the state supported by this middleware.
19 * @template D The type of Dispatch of the store where this middleware is
20 *   installed.
21 */
22export interface Middleware<
23  _DispatchExt = {}, // TODO: remove unused component (breaking change)
24  S = any,
25  D extends Dispatch = Dispatch
26> {
27  (api: MiddlewareAPI<D, S>): (
28    next: D
29  ) => (action: D extends Dispatch<infer A> ? A : never) => any
30}
31