1 | /**
|
2 | * An *action* is a plain object that represents an intention to change the
|
3 | * state. Actions are the only way to get data into the store. Any data,
|
4 | * whether from UI events, network callbacks, or other sources such as
|
5 | * WebSockets needs to eventually be dispatched as actions.
|
6 | *
|
7 | * Actions must have a `type` field that indicates the type of action being
|
8 | * performed. Types can be defined as constants and imported from another
|
9 | * module. These must be strings, as strings are serializable.
|
10 | *
|
11 | * Other than `type`, the structure of an action object is really up to you.
|
12 | * If you're interested, check out Flux Standard Action for recommendations on
|
13 | * how actions should be constructed.
|
14 | *
|
15 | * @template T the type of the action's `type` tag.
|
16 | */
|
17 | // this needs to be a type, not an interface
|
18 | // https://github.com/microsoft/TypeScript/issues/15300
|
19 | export type Action<T extends string = string> = {
|
20 | type: T
|
21 | }
|
22 |
|
23 | /**
|
24 | * An Action type which accepts any other properties.
|
25 | * This is mainly for the use of the `Reducer` type.
|
26 | * This is not part of `Action` itself to prevent types that extend `Action` from
|
27 | * having an index signature.
|
28 | */
|
29 | export interface UnknownAction extends Action {
|
30 | // Allows any extra properties to be defined in an action.
|
31 | [extraProps: string]: unknown
|
32 | }
|
33 |
|
34 | /**
|
35 | * An Action type which accepts any other properties.
|
36 | * This is mainly for the use of the `Reducer` type.
|
37 | * This is not part of `Action` itself to prevent types that extend `Action` from
|
38 | * having an index signature.
|
39 | * @deprecated use Action or UnknownAction instead
|
40 | */
|
41 | export interface AnyAction extends Action {
|
42 | // Allows any extra properties to be defined in an action.
|
43 | [extraProps: string]: any
|
44 | }
|
45 |
|
46 | /* action creators */
|
47 |
|
48 | /**
|
49 | * An *action creator* is, quite simply, a function that creates an action. Do
|
50 | * not confuse the two terms—again, an action is a payload of information, and
|
51 | * an action creator is a factory that creates an action.
|
52 | *
|
53 | * Calling an action creator only produces an action, but does not dispatch
|
54 | * it. You need to call the store's `dispatch` function to actually cause the
|
55 | * mutation. Sometimes we say *bound action creators* to mean functions that
|
56 | * call an action creator and immediately dispatch its result to a specific
|
57 | * store instance.
|
58 | *
|
59 | * If an action creator needs to read the current state, perform an API call,
|
60 | * or cause a side effect, like a routing transition, it should return an
|
61 | * async action instead of an action.
|
62 | *
|
63 | * @template A Returned action type.
|
64 | */
|
65 | export interface ActionCreator<A, P extends any[] = any[]> {
|
66 | (...args: P): A
|
67 | }
|
68 |
|
69 | /**
|
70 | * Object whose values are action creator functions.
|
71 | */
|
72 | export interface ActionCreatorsMapObject<A = any, P extends any[] = any[]> {
|
73 | [key: string]: ActionCreator<A, P>
|
74 | }
|