File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
packages/toolkit/src/entities/tests Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { createEntityAdapter , createSlice } from "../.." ;
2
+ import type { PayloadAction , SliceCaseReducers } from "../.." ;
3
+ import type { DraftableIdSelector , IdSelector } from "../models" ;
4
+
5
+ interface EntitySliceArgs < T > {
6
+ name : string
7
+ modelReducer : SliceCaseReducers < T >
8
+ selectId : IdSelector < T > // unusable
9
+ selectDraftableId : DraftableIdSelector < T >
10
+ }
11
+
12
+ // currently this never runs, it only serves to illustrate that the containing calls are type valid
13
+ function entitySliceEnhancer < T > ( {
14
+ name,
15
+ modelReducer,
16
+ selectId : undraftableSelectId ,
17
+ selectDraftableId
18
+ } : EntitySliceArgs < T > ) {
19
+ const modelAdapter = createEntityAdapter < T > ( {
20
+ selectId : selectDraftableId // undraftableSelectId would give an interesting error
21
+ } ) ;
22
+
23
+ return createSlice ( {
24
+ name,
25
+ initialState : modelAdapter . getInitialState ( ) ,
26
+ reducers : {
27
+ oneAdded ( state , action : PayloadAction < T > ) {
28
+ modelAdapter . addOne (
29
+ state ,
30
+ action . payload
31
+ )
32
+ } ,
33
+ ...modelReducer
34
+ }
35
+ } )
36
+ }
You can’t perform that action at this time.
0 commit comments