Skip to content

Commit

Permalink
Update all READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed Jan 16, 2024
1 parent 2837b25 commit 27fe907
Show file tree
Hide file tree
Showing 4 changed files with 737 additions and 109 deletions.
1 change: 1 addition & 0 deletions packages/rtk-codemods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ node ./bin/cli.js <TRANSFORM NAME> path/of/files/ or/some**/*glob.js

- [createReducerBuilder](transforms/createReducerBuilder/README.md)
- [createSliceBuilder](transforms/createSliceBuilder/README.md)
- [createSliceReducerBuilder](transforms/createSliceReducerBuilder/README.md)
<!--TRANSFORMS_END-->

## Contributing
Expand Down
212 changes: 177 additions & 35 deletions packages/rtk-codemods/transforms/createReducerBuilder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,159 @@ node ./bin/cli.js createReducerBuilder path/of/files/ or/some**/*glob.js

## <!--FIXTURES_CONTENT_START-->

---

<a id="basic-ts">**basic-ts**</a>

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

```ts
createReducer(initialState, {
[todoAdded]: (state: SliceState, action: PayloadAction<string>) => {
import type { PayloadAction } from '@reduxjs/toolkit'
import { createEntityAdapter, createReducer } from '@reduxjs/toolkit'

export interface Todo {
id: string
title: string
}

export const todoAdapter = createEntityAdapter<Todo>()

const todoInitialState = todoAdapter.getInitialState()

export type TodoSliceState = typeof todoInitialState

const { addOne } = todoAdapter

createReducer(todoInitialState, {
[todoAdded1a]: (state: TodoSliceState, action: PayloadAction<string>) => {
// stuff
},
});
[todoAdded1b]: (state: TodoSliceState, action: PayloadAction<string>) =>
action.payload,
[todoAdded1c + 'test']: (
state: TodoSliceState,
action: PayloadAction<string>
) => {
// stuff
},
[todoAdded1d](state: TodoSliceState, action: PayloadAction<string>) {
// stuff
},
[todoAdded1e]: function (
state: TodoSliceState,
action: PayloadAction<string>
) {
// stuff
},
todoAdded1f: (state: TodoSliceState, action: PayloadAction<string>) => {
//stuff
},
[todoAdded1g]: addOne,
todoAdded1h: todoAdapter.addOne
})

createReducer(initialState, {
[todoAdded](state: SliceState, action: PayloadAction<string>) {
createReducer(todoInitialState, {
[todoAdded2a]: (state: TodoSliceState, action: PayloadAction<string>) => {
// stuff
},
});
[todoAdded2b](state: TodoSliceState, action: PayloadAction<string>) {
// stuff
},
[todoAdded2c]: function (
state: TodoSliceState,
action: PayloadAction<string>
) {
// stuff
}
})
```

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

```ts
createReducer(initialState, (builder) => {
builder.addCase(todoAdded, (state: SliceState, action: PayloadAction<string>) => {
// stuff
});
});

createReducer(initialState, (builder) => {
builder.addCase(todoAdded, (state: SliceState, action: PayloadAction<string>) => {
// stuff
});
});
import type { PayloadAction } from '@reduxjs/toolkit'
import { createEntityAdapter, createReducer } from '@reduxjs/toolkit'

export interface Todo {
id: string
title: string
}

export const todoAdapter = createEntityAdapter<Todo>()

const todoInitialState = todoAdapter.getInitialState()

export type TodoSliceState = typeof todoInitialState

const { addOne } = todoAdapter

createReducer(todoInitialState, (builder) => {
builder.addCase(
todoAdded1a,
(state: TodoSliceState, action: PayloadAction<string>) => {
// stuff
}
)

builder.addCase(
todoAdded1b,
(state: TodoSliceState, action: PayloadAction<string>) => action.payload
)

builder.addCase(
todoAdded1c + 'test',
(state: TodoSliceState, action: PayloadAction<string>) => {
// stuff
}
)

builder.addCase(
todoAdded1d,
(state: TodoSliceState, action: PayloadAction<string>) => {
// stuff
}
)

builder.addCase(
todoAdded1e,
(state: TodoSliceState, action: PayloadAction<string>) => {
// stuff
}
)

builder.addCase(
todoAdded1f,
(state: TodoSliceState, action: PayloadAction<string>) => {
//stuff
}
)

builder.addCase(todoAdded1g, addOne)
builder.addCase(todoAdded1h, todoAdapter.addOne)
})

createReducer(todoInitialState, (builder) => {
builder.addCase(
todoAdded2a,
(state: TodoSliceState, action: PayloadAction<string>) => {
// stuff
}
)

builder.addCase(
todoAdded2b,
(state: TodoSliceState, action: PayloadAction<string>) => {
// stuff
}
)

builder.addCase(
todoAdded2c,
(state: TodoSliceState, action: PayloadAction<string>) => {
// stuff
}
)
})
```

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

```js
createReducer(initialState, {
import { createEntityAdapter, createReducer } from '@reduxjs/toolkit'

export const todoAdapter = createEntityAdapter()

const todoInitialState = todoAdapter.getInitialState()

const { addOne } = todoAdapter

createReducer(todoInitialState, {
[todoAdded1a]: (state, action) => {
// stuff
},
Expand All @@ -89,9 +218,11 @@ createReducer(initialState, {
todoAdded1f: (state, action) => {
//stuff
},
});
[todoAdded1g]: addOne,
todoAdded1h: todoAdapter.addOne
})

createReducer(initialState, {
createReducer(todoInitialState, {
[todoAdded2a]: (state, action) => {
// stuff
},
Expand All @@ -100,50 +231,61 @@ createReducer(initialState, {
},
[todoAdded2c]: function (state, action) {
// stuff
},
});
}
})
```

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

```js
createReducer(initialState, (builder) => {
import { createEntityAdapter, createReducer } from '@reduxjs/toolkit'

export const todoAdapter = createEntityAdapter()

const todoInitialState = todoAdapter.getInitialState()

const { addOne } = todoAdapter

createReducer(todoInitialState, (builder) => {
builder.addCase(todoAdded1a, (state, action) => {
// stuff
});
})

builder.addCase(todoAdded1b, (state, action) => action.payload);
builder.addCase(todoAdded1b, (state, action) => action.payload)

builder.addCase(todoAdded1c + 'test', (state, action) => {
// stuff
});
})

builder.addCase(todoAdded1d, (state, action) => {
// stuff
});
})

builder.addCase(todoAdded1e, (state, action) => {
// stuff
});
})

builder.addCase(todoAdded1f, (state, action) => {
//stuff
});
});
})

builder.addCase(todoAdded1g, addOne)
builder.addCase(todoAdded1h, todoAdapter.addOne)
})

createReducer(initialState, (builder) => {
createReducer(todoInitialState, (builder) => {
builder.addCase(todoAdded2a, (state, action) => {
// stuff
});
})

builder.addCase(todoAdded2b, (state, action) => {
// stuff
});
})

builder.addCase(todoAdded2c, (state, action) => {
// stuff
});
});
})
})
```

<!--FIXTURES_CONTENT_END-->
Loading

0 comments on commit 27fe907

Please sign in to comment.