Skip to content

Commit 27fe907

Browse files
committed
Update all READMEs
1 parent 2837b25 commit 27fe907

File tree

4 files changed

+737
-109
lines changed

4 files changed

+737
-109
lines changed

packages/rtk-codemods/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ node ./bin/cli.js <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
2727

2828
- [createReducerBuilder](transforms/createReducerBuilder/README.md)
2929
- [createSliceBuilder](transforms/createSliceBuilder/README.md)
30+
- [createSliceReducerBuilder](transforms/createSliceReducerBuilder/README.md)
3031
<!--TRANSFORMS_END-->
3132

3233
## Contributing

packages/rtk-codemods/transforms/createReducerBuilder/README.md

Lines changed: 177 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,159 @@ node ./bin/cli.js createReducerBuilder path/of/files/ or/some**/*glob.js
3131

3232
## <!--FIXTURES_CONTENT_START-->
3333

34+
---
35+
3436
<a id="basic-ts">**basic-ts**</a>
3537

3638
**Input** (<small>[basic-ts.input.ts](transforms\createReducerBuilder__testfixtures__\basic-ts.input.ts)</small>):
3739

3840
```ts
39-
createReducer(initialState, {
40-
[todoAdded]: (state: SliceState, action: PayloadAction<string>) => {
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>) => {
4159
// stuff
4260
},
43-
});
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+
})
4484

45-
createReducer(initialState, {
46-
[todoAdded](state: SliceState, action: PayloadAction<string>) {
85+
createReducer(todoInitialState, {
86+
[todoAdded2a]: (state: TodoSliceState, action: PayloadAction<string>) => {
4787
// stuff
4888
},
49-
});
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+
})
5099
```
51100

52101
**Output** (<small>[basic-ts.output.ts](transforms\createReducerBuilder__testfixtures__\basic-ts.output.ts)</small>):
53102

54103
```ts
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-
});
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+
})
66187
```
67188

68189
---
@@ -72,7 +193,15 @@ createReducer(initialState, (builder) => {
72193
**Input** (<small>[basic.input.js](transforms\createReducerBuilder__testfixtures__\basic.input.js)</small>):
73194

74195
```js
75-
createReducer(initialState, {
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, {
76205
[todoAdded1a]: (state, action) => {
77206
// stuff
78207
},
@@ -89,9 +218,11 @@ createReducer(initialState, {
89218
todoAdded1f: (state, action) => {
90219
//stuff
91220
},
92-
});
221+
[todoAdded1g]: addOne,
222+
todoAdded1h: todoAdapter.addOne
223+
})
93224

94-
createReducer(initialState, {
225+
createReducer(todoInitialState, {
95226
[todoAdded2a]: (state, action) => {
96227
// stuff
97228
},
@@ -100,50 +231,61 @@ createReducer(initialState, {
100231
},
101232
[todoAdded2c]: function (state, action) {
102233
// stuff
103-
},
104-
});
234+
}
235+
})
105236
```
106237

107238
**Output** (<small>[basic.output.js](transforms\createReducerBuilder__testfixtures__\basic.output.js)</small>):
108239

109240
```js
110-
createReducer(initialState, (builder) => {
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) => {
111250
builder.addCase(todoAdded1a, (state, action) => {
112251
// stuff
113-
});
252+
})
114253

115-
builder.addCase(todoAdded1b, (state, action) => action.payload);
254+
builder.addCase(todoAdded1b, (state, action) => action.payload)
116255

117256
builder.addCase(todoAdded1c + 'test', (state, action) => {
118257
// stuff
119-
});
258+
})
120259

121260
builder.addCase(todoAdded1d, (state, action) => {
122261
// stuff
123-
});
262+
})
124263

125264
builder.addCase(todoAdded1e, (state, action) => {
126265
// stuff
127-
});
266+
})
128267

129268
builder.addCase(todoAdded1f, (state, action) => {
130269
//stuff
131-
});
132-
});
270+
})
271+
272+
builder.addCase(todoAdded1g, addOne)
273+
builder.addCase(todoAdded1h, todoAdapter.addOne)
274+
})
133275

134-
createReducer(initialState, (builder) => {
276+
createReducer(todoInitialState, (builder) => {
135277
builder.addCase(todoAdded2a, (state, action) => {
136278
// stuff
137-
});
279+
})
138280

139281
builder.addCase(todoAdded2b, (state, action) => {
140282
// stuff
141-
});
283+
})
142284

143285
builder.addCase(todoAdded2c, (state, action) => {
144286
// stuff
145-
});
146-
});
287+
})
288+
})
147289
```
148290

149291
<!--FIXTURES_CONTENT_END-->

0 commit comments

Comments
 (0)