Skip to content
This repository was archived by the owner on Feb 3, 2020. It is now read-only.

Commit e0bd7c7

Browse files
docs: include return value overide in readme and example
1 parent 927a475 commit e0bd7c7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { createAction, handleAction, reduceReducers } from 'redux-ts-utils';
2424
const increment = createAction<void>('increment');
2525
const decrement = createAction<void>('decrement');
2626
const add = createAction<number>('add');
27+
const override = createAction<number>('override');
2728

2829
// Reducer
2930

@@ -45,6 +46,9 @@ const reducer = reduceReducers<State>([
4546
handleAction(add, (state, { payload }) => {
4647
state.counter += payload;
4748
}),
49+
handleAction(override, (_, { payload }) => ({
50+
counter: payload,
51+
})),
4852
], initialState);
4953

5054
// Store
@@ -142,6 +146,9 @@ object. [`immer`] will also provide you with a mapped type (`Draft`) of your
142146
state with all `readonly` modifiers removed (it will also remove `Readonly`
143147
mapped types and convert `ReadonlyArray`s to standard arrays).
144148

149+
If your mutation function returns a value other than `undefined`, and does not mutate the
150+
incoming state object, that return value will become the new state instead.
151+
145152
### `reduceReducers<S>(reducers: Reducer[], initialState?: S)`
146153

147154
The `reduceReducers` function takes an array of reducer functions and an

src/example.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createAction, handleAction, reduceReducers } from '.';
88
const increment = createAction<void>('increment');
99
const decrement = createAction<void>('decrement');
1010
const add = createAction<number>('add');
11+
const override = createAction<number>('override');
1112

1213
// Reducer
1314

@@ -29,6 +30,9 @@ const reducer = reduceReducers<State>([
2930
handleAction(add, (state, { payload }) => {
3031
state.counter += payload;
3132
}),
33+
handleAction(override, (_, { payload }) => ({
34+
counter: payload,
35+
})),
3236
], initialState);
3337

3438
// Store

0 commit comments

Comments
 (0)