1 | import { Dispatch } from './store'
|
2 |
|
3 | export 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 | */
|
22 | export interface Middleware<
|
23 | _DispatchExt = {}, // TODO: see if this can be used in type definition somehow (can't be removed, as is used to get final dispatch type)
|
24 | S = any,
|
25 | D extends Dispatch = Dispatch
|
26 | > {
|
27 | (api: MiddlewareAPI<D, S>): (
|
28 | next: (action: unknown) => unknown
|
29 | ) => (action: unknown) => unknown
|
30 | }
|