@@ -210,11 +210,7 @@ interface InternalReducerHandlingContext<State> {
210
210
actionCreators : Record < string , any >
211
211
}
212
212
213
- export interface ReducerHandlingContext <
214
- State ,
215
- Name extends string = string ,
216
- ReducerPath extends string = Name ,
217
- > {
213
+ export interface ReducerHandlingContext < State > {
218
214
/**
219
215
* Adds a case reducer to handle a single action type.
220
216
* @param actionCreator - Either a plain action type string, or an action creator generated by [`createAction`](./createAction) that can be used to determine the action type.
@@ -223,7 +219,7 @@ export interface ReducerHandlingContext<
223
219
addCase < ActionCreator extends TypedActionCreator < string > > (
224
220
actionCreator : ActionCreator ,
225
221
reducer : CaseReducer < State , ReturnType < ActionCreator > > ,
226
- ) : ReducerHandlingContext < State , Name , ReducerPath >
222
+ ) : ReducerHandlingContext < State >
227
223
/**
228
224
* Adds a case reducer to handle a single action type.
229
225
* @param actionCreator - Either a plain action type string, or an action creator generated by [`createAction`](./createAction) that can be used to determine the action type.
@@ -232,7 +228,7 @@ export interface ReducerHandlingContext<
232
228
addCase < Type extends string , A extends Action < Type > > (
233
229
type : Type ,
234
230
reducer : CaseReducer < State , A > ,
235
- ) : ReducerHandlingContext < State , Name , ReducerPath >
231
+ ) : ReducerHandlingContext < State >
236
232
237
233
/**
238
234
* Allows you to match incoming actions against your own filter function instead of only the `action.type` property.
@@ -248,7 +244,7 @@ export interface ReducerHandlingContext<
248
244
addMatcher < A > (
249
245
matcher : TypeGuard < A > ,
250
246
reducer : CaseReducer < State , A extends Action ? A : A & Action > ,
251
- ) : ReducerHandlingContext < State , Name , ReducerPath >
247
+ ) : ReducerHandlingContext < State >
252
248
/**
253
249
* Add an action to be exposed under the final `slice.actions[reducerName]` key.
254
250
*
@@ -262,9 +258,7 @@ export interface ReducerHandlingContext<
262
258
*
263
259
* dispatch(addPost(post))
264
260
*/
265
- exposeAction (
266
- actionCreator : unknown ,
267
- ) : ReducerHandlingContext < State , Name , ReducerPath >
261
+ exposeAction ( actionCreator : unknown ) : ReducerHandlingContext < State >
268
262
269
263
/**
270
264
* Add a case reducer to be exposed under the final `slice.caseReducers[reducerName]` key.
@@ -279,39 +273,28 @@ export interface ReducerHandlingContext<
279
273
*
280
274
* slice.caseReducers.addPost([], addPost(post))
281
275
*/
282
- exposeCaseReducer (
283
- reducer : unknown ,
284
- ) : ReducerHandlingContext < State , Name , ReducerPath >
276
+ exposeCaseReducer ( reducer : unknown ) : ReducerHandlingContext < State >
285
277
286
278
/**
287
279
* Provides access to the initial state value given to the slice.
288
280
* If a lazy state initializer was provided, it will be called and a fresh value returned.
289
281
*/
290
282
getInitialState ( ) : State
291
283
292
- /**
293
- * The `name` option provided for the slice.
294
- */
295
- name : Name
296
-
297
- /**
298
- * The `reducerPath` option provided for the slice.
299
- * Defaults to `name` if not provided.
300
- */
301
- reducerPath : ReducerPath
302
-
303
284
/**
304
285
* Tries to select the slice's state from a possible root state shape, using `reducerPath`.
305
286
* Throws an error if slice's state is not found.
306
287
*
307
288
* *Note that only the original `reducerPath` option is used - if a different `reducerPath` is used when injecting, this will not be reflected.*
308
289
*/
309
- selectSlice ( state : Record < ReducerPath , State > ) : State
290
+ selectSlice ( state : Record < string , State > ) : State
310
291
}
311
292
312
293
export interface ReducerDetails {
313
294
/** The name of the slice */
314
295
sliceName : string
296
+ /** The reducerPath option passed for the slice. Defaults to `sliceName` if not provided. */
297
+ reducerPath : string
315
298
/** The key the reducer was defined under */
316
299
reducerName : string
317
300
/** The predefined action type, i.e. `${sliceName}/${reducerName}` */
@@ -367,10 +350,10 @@ export type ReducerCreator<Type extends RegisteredReducerType> = {
367
350
} & ( ReducerDefinitionsForType < Type > extends never
368
351
? { }
369
352
: {
370
- handle < State , Name extends string , ReducerPath extends string > (
353
+ handle < State > (
371
354
details : ReducerDetails ,
372
355
definition : ReducerDefinitionsForType < Type > ,
373
- context : ReducerHandlingContext < State , Name , ReducerPath > ,
356
+ context : ReducerHandlingContext < State > ,
374
357
) : void
375
358
} )
376
359
@@ -966,7 +949,7 @@ export function buildCreateSlice<
966
949
}
967
950
968
951
function getContext ( { reducerName } : ReducerDetails ) {
969
- const context : ReducerHandlingContext < State , Name , ReducerPath > = {
952
+ const context : ReducerHandlingContext < State > = {
970
953
addCase (
971
954
typeOrActionCreator : string | TypedActionCreator < any > ,
972
955
reducer : CaseReducer < State > ,
@@ -1014,8 +997,6 @@ export function buildCreateSlice<
1014
997
return context
1015
998
} ,
1016
999
getInitialState,
1017
- name,
1018
- reducerPath,
1019
1000
selectSlice ( state ) {
1020
1001
const sliceState = state [ reducerPath ]
1021
1002
if ( typeof sliceState === 'undefined' ) {
@@ -1045,6 +1026,7 @@ export function buildCreateSlice<
1045
1026
const reducerDetails : ReducerDetails = {
1046
1027
sliceName : name ,
1047
1028
reducerName,
1029
+ reducerPath,
1048
1030
type : getType ( name , reducerName ) ,
1049
1031
}
1050
1032
handler (
@@ -1060,6 +1042,7 @@ export function buildCreateSlice<
1060
1042
const reducerDetails : ReducerDetails = {
1061
1043
sliceName : name ,
1062
1044
reducerName,
1045
+ reducerPath,
1063
1046
type : getType ( name , reducerName ) ,
1064
1047
}
1065
1048
const handler =
0 commit comments