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

Commit

Permalink
docs: include return value overide in readme and example
Browse files Browse the repository at this point in the history
  • Loading branch information
cinnabarcaracal committed Feb 7, 2019
1 parent 927a475 commit e0bd7c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { createAction, handleAction, reduceReducers } from 'redux-ts-utils';
const increment = createAction<void>('increment');
const decrement = createAction<void>('decrement');
const add = createAction<number>('add');
const override = createAction<number>('override');

// Reducer

Expand All @@ -45,6 +46,9 @@ const reducer = reduceReducers<State>([
handleAction(add, (state, { payload }) => {
state.counter += payload;
}),
handleAction(override, (_, { payload }) => ({
counter: payload,
})),
], initialState);

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

If your mutation function returns a value other than `undefined`, and does not mutate the
incoming state object, that return value will become the new state instead.

### `reduceReducers<S>(reducers: Reducer[], initialState?: S)`

The `reduceReducers` function takes an array of reducer functions and an
Expand Down
4 changes: 4 additions & 0 deletions src/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createAction, handleAction, reduceReducers } from '.';
const increment = createAction<void>('increment');
const decrement = createAction<void>('decrement');
const add = createAction<number>('add');
const override = createAction<number>('override');

// Reducer

Expand All @@ -29,6 +30,9 @@ const reducer = reduceReducers<State>([
handleAction(add, (state, { payload }) => {
state.counter += payload;
}),
handleAction(override, (_, { payload }) => ({
counter: payload,
})),
], initialState);

// Store
Expand Down

0 comments on commit e0bd7c7

Please sign in to comment.