@@ -31,159 +31,38 @@ node ./bin/cli.js createReducerBuilder path/of/files/ or/some**/*glob.js
31
31
32
32
## <!-- FIXTURES_CONTENT_START-->
33
33
34
- ---
35
-
36
34
<a id =" basic-ts " >** basic-ts** </a >
37
35
38
36
** Input** (<small >[ basic-ts.input.ts] ( transforms\createReducerBuilder__testfixtures__\basic-ts.input.ts ) </small >):
39
37
40
38
``` ts
41
- import type { PayloadAction } from ' @reduxjs/toolkit'
42
- import { createEntityAdapter , createReducer } from ' @reduxjs/toolkit'
43
-
44
- export interface Todo {
45
- id: string
46
- title: string
47
- }
48
-
49
- export const todoAdapter = createEntityAdapter <Todo >()
50
-
51
- const todoInitialState = todoAdapter .getInitialState ()
52
-
53
- export type TodoSliceState = typeof todoInitialState
54
-
55
- const { addOne } = todoAdapter
56
-
57
- createReducer (todoInitialState , {
58
- [todoAdded1a ]: (state : TodoSliceState , action : PayloadAction <string >) => {
39
+ createReducer (initialState , {
40
+ [todoAdded ]: (state : SliceState , action : PayloadAction <string >) => {
59
41
// stuff
60
42
},
61
- [todoAdded1b ]: (state : TodoSliceState , action : PayloadAction <string >) =>
62
- action .payload ,
63
- [todoAdded1c + ' test' ]: (
64
- state : TodoSliceState ,
65
- action : PayloadAction <string >
66
- ) => {
67
- // stuff
68
- },
69
- [todoAdded1d ](state : TodoSliceState , action : PayloadAction <string >) {
70
- // stuff
71
- },
72
- [todoAdded1e ]: function (
73
- state : TodoSliceState ,
74
- action : PayloadAction <string >
75
- ) {
76
- // stuff
77
- },
78
- todoAdded1f : (state : TodoSliceState , action : PayloadAction <string >) => {
79
- // stuff
80
- },
81
- [todoAdded1g ]: addOne ,
82
- todoAdded1h: todoAdapter .addOne
83
- })
43
+ });
84
44
85
- createReducer (todoInitialState , {
86
- [todoAdded2a ]: (state : TodoSliceState , action : PayloadAction <string >) => {
45
+ createReducer (initialState , {
46
+ [todoAdded ] (state : SliceState , action : PayloadAction <string >) {
87
47
// stuff
88
48
},
89
- [todoAdded2b ](state : TodoSliceState , action : PayloadAction <string >) {
90
- // stuff
91
- },
92
- [todoAdded2c ]: function (
93
- state : TodoSliceState ,
94
- action : PayloadAction <string >
95
- ) {
96
- // stuff
97
- }
98
- })
49
+ });
99
50
```
100
51
101
52
** Output** (<small >[ basic-ts.output.ts] ( transforms\createReducerBuilder__testfixtures__\basic-ts.output.ts ) </small >):
102
53
103
54
``` ts
104
- import type { PayloadAction } from ' @reduxjs/toolkit'
105
- import { createEntityAdapter , createReducer } from ' @reduxjs/toolkit'
106
-
107
- export interface Todo {
108
- id: string
109
- title: string
110
- }
111
-
112
- export const todoAdapter = createEntityAdapter <Todo >()
113
-
114
- const todoInitialState = todoAdapter .getInitialState ()
115
-
116
- export type TodoSliceState = typeof todoInitialState
117
-
118
- const { addOne } = todoAdapter
119
-
120
- createReducer (todoInitialState , (builder ) => {
121
- builder .addCase (
122
- todoAdded1a ,
123
- (state : TodoSliceState , action : PayloadAction <string >) => {
124
- // stuff
125
- }
126
- )
127
-
128
- builder .addCase (
129
- todoAdded1b ,
130
- (state : TodoSliceState , action : PayloadAction <string >) => action .payload
131
- )
132
-
133
- builder .addCase (
134
- todoAdded1c + ' test' ,
135
- (state : TodoSliceState , action : PayloadAction <string >) => {
136
- // stuff
137
- }
138
- )
139
-
140
- builder .addCase (
141
- todoAdded1d ,
142
- (state : TodoSliceState , action : PayloadAction <string >) => {
143
- // stuff
144
- }
145
- )
146
-
147
- builder .addCase (
148
- todoAdded1e ,
149
- (state : TodoSliceState , action : PayloadAction <string >) => {
150
- // stuff
151
- }
152
- )
153
-
154
- builder .addCase (
155
- todoAdded1f ,
156
- (state : TodoSliceState , action : PayloadAction <string >) => {
157
- // stuff
158
- }
159
- )
160
-
161
- builder .addCase (todoAdded1g , addOne )
162
- builder .addCase (todoAdded1h , todoAdapter .addOne )
163
- })
164
-
165
- createReducer (todoInitialState , (builder ) => {
166
- builder .addCase (
167
- todoAdded2a ,
168
- (state : TodoSliceState , action : PayloadAction <string >) => {
169
- // stuff
170
- }
171
- )
172
-
173
- builder .addCase (
174
- todoAdded2b ,
175
- (state : TodoSliceState , action : PayloadAction <string >) => {
176
- // stuff
177
- }
178
- )
179
-
180
- builder .addCase (
181
- todoAdded2c ,
182
- (state : TodoSliceState , action : PayloadAction <string >) => {
183
- // stuff
184
- }
185
- )
186
- })
55
+ createReducer (initialState , (builder ) => {
56
+ builder .addCase (todoAdded , (state : SliceState , action : PayloadAction <string >) => {
57
+ // stuff
58
+ });
59
+ });
60
+
61
+ createReducer (initialState , (builder ) => {
62
+ builder .addCase (todoAdded , (state : SliceState , action : PayloadAction <string >) => {
63
+ // stuff
64
+ });
65
+ });
187
66
```
188
67
189
68
---
@@ -193,15 +72,7 @@ createReducer(todoInitialState, (builder) => {
193
72
** Input** (<small >[ basic.input.js] ( transforms\createReducerBuilder__testfixtures__\basic.input.js ) </small >):
194
73
195
74
``` js
196
- import { createEntityAdapter , createReducer } from ' @reduxjs/toolkit'
197
-
198
- export const todoAdapter = createEntityAdapter ()
199
-
200
- const todoInitialState = todoAdapter .getInitialState ()
201
-
202
- const { addOne } = todoAdapter
203
-
204
- createReducer (todoInitialState, {
75
+ createReducer (initialState, {
205
76
[todoAdded1a]: (state , action ) => {
206
77
// stuff
207
78
},
@@ -218,11 +89,9 @@ createReducer(todoInitialState, {
218
89
todoAdded1f : (state , action ) => {
219
90
// stuff
220
91
},
221
- [todoAdded1g]: addOne,
222
- todoAdded1h: todoAdapter .addOne
223
- })
92
+ });
224
93
225
- createReducer (todoInitialState , {
94
+ createReducer (initialState , {
226
95
[todoAdded2a]: (state , action ) => {
227
96
// stuff
228
97
},
@@ -231,61 +100,50 @@ createReducer(todoInitialState, {
231
100
},
232
101
[todoAdded2c]: function (state , action ) {
233
102
// stuff
234
- }
235
- })
103
+ },
104
+ });
236
105
```
237
106
238
107
** Output** (<small >[ basic.output.js] ( transforms\createReducerBuilder__testfixtures__\basic.output.js ) </small >):
239
108
240
109
``` js
241
- import { createEntityAdapter , createReducer } from ' @reduxjs/toolkit'
242
-
243
- export const todoAdapter = createEntityAdapter ()
244
-
245
- const todoInitialState = todoAdapter .getInitialState ()
246
-
247
- const { addOne } = todoAdapter
248
-
249
- createReducer (todoInitialState, (builder ) => {
110
+ createReducer (initialState, (builder ) => {
250
111
builder .addCase (todoAdded1a, (state , action ) => {
251
112
// stuff
252
- })
113
+ });
253
114
254
- builder .addCase (todoAdded1b, (state , action ) => action .payload )
115
+ builder .addCase (todoAdded1b, (state , action ) => action .payload );
255
116
256
117
builder .addCase (todoAdded1c + ' test' , (state , action ) => {
257
118
// stuff
258
- })
119
+ });
259
120
260
121
builder .addCase (todoAdded1d, (state , action ) => {
261
122
// stuff
262
- })
123
+ });
263
124
264
125
builder .addCase (todoAdded1e, (state , action ) => {
265
126
// stuff
266
- })
127
+ });
267
128
268
129
builder .addCase (todoAdded1f, (state , action ) => {
269
130
// stuff
270
- })
271
-
272
- builder .addCase (todoAdded1g, addOne)
273
- builder .addCase (todoAdded1h, todoAdapter .addOne )
274
- })
131
+ });
132
+ });
275
133
276
- createReducer (todoInitialState , (builder ) => {
134
+ createReducer (initialState , (builder ) => {
277
135
builder .addCase (todoAdded2a, (state , action ) => {
278
136
// stuff
279
- })
137
+ });
280
138
281
139
builder .addCase (todoAdded2b, (state , action ) => {
282
140
// stuff
283
- })
141
+ });
284
142
285
143
builder .addCase (todoAdded2c, (state , action ) => {
286
144
// stuff
287
- })
288
- })
145
+ });
146
+ });
289
147
```
290
148
291
149
<!-- FIXTURES_CONTENT_END-->
0 commit comments