File tree 3 files changed +30
-1
lines changed
3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,21 @@ export function createReducer<
56
56
S ,
57
57
CR extends CaseReducers < S , any > = CaseReducers < S , any >
58
58
> ( initialState : S , actionsMap : CR ) : Reducer < S >
59
-
59
+ /**
60
+ * A utility function that allows defining a reducer as a mapping from action
61
+ * type to *case reducer* functions that handle these action types. The
62
+ * reducer's initial state is passed as the first argument.
63
+ *
64
+ * The body of every case reducer is implicitly wrapped with a call to
65
+ * `produce()` from the [immer](https://github.com/mweststrate/immer) library.
66
+ * This means that rather than returning a new state object, you can also
67
+ * mutate the passed-in state object directly; these mutations will then be
68
+ * automatically and efficiently translated into copies, giving you both
69
+ * convenience and immutability.
70
+ * @param initialState The initial state to be returned by the reducer.
71
+ * @param builderCallback A callback that receives a *builder* object to define
72
+ * case reducers via calls to `builder.addCase(actionCreatorOrType, reducer)`.
73
+ */
60
74
export function createReducer < S > (
61
75
initialState : S ,
62
76
builderCallback : ( builder : ActionReducerMapBuilder < S > ) => void
Original file line number Diff line number Diff line change @@ -76,6 +76,8 @@ export interface CreateSliceOptions<
76
76
* A mapping from action types to action-type-specific *case reducer*
77
77
* functions. These reducers should have existing action types used
78
78
* as the keys, and action creators will _not_ be generated.
79
+ * Alternatively, a callback that receives a *builder* object to define
80
+ * case reducers via calls to `builder.addCase(actionCreatorOrType, reducer)`.
79
81
*/
80
82
extraReducers ?:
81
83
| CaseReducers < NoInfer < State > , any >
Original file line number Diff line number Diff line change @@ -6,11 +6,24 @@ export interface TypedActionCreator<Type extends string> {
6
6
type : Type
7
7
}
8
8
9
+ /**
10
+ * A builder for an action <-> reducer map.
11
+ */
9
12
export interface ActionReducerMapBuilder < State > {
13
+ /**
14
+ * Add a case reducer for actions created by this action creator.
15
+ * @param actionCreator
16
+ * @param reducer
17
+ */
10
18
addCase < ActionCreator extends TypedActionCreator < string > > (
11
19
actionCreator : ActionCreator ,
12
20
reducer : CaseReducer < State , ReturnType < ActionCreator > >
13
21
) : ActionReducerMapBuilder < State >
22
+ /**
23
+ * Add a case reducer for actions with the specified type.
24
+ * @param type
25
+ * @param reducer
26
+ */
14
27
addCase < Type extends string , A extends Action < Type > > (
15
28
type : Type ,
16
29
reducer : CaseReducer < State , A >
You can’t perform that action at this time.
0 commit comments