Skip to content

Commit

Permalink
buildReducer API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkis committed Feb 20, 2017
1 parent eb7c03c commit 98c3ffe
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/api/buildReducer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# `buildReducer(handlers, initialState)`

Creates a Redux compatible [Reducer](http://redux.js.org/docs/basics/Reducers.html).

#### Arguments

1. `handlers` *(Array<UnwrapperHandlerPair>)*: An array of `UnwrapperHandlerPair` which is just an object consisting of two fields: `unwrapper` and `handler`

2. [`initialState`] *(any)*: Initial state to be used as a default value for the reducer.

#### Returns

`reducer` *(Function)*: Plain old JavaScript function which can be used as Redux reducer.

#### Example

```js
import { buildReducer, buildUnwrapper } from 'prism';

const reducer = buildReducer([{
unwrapper: buildUnwrapper('Increment'),
handler: state => state + 1
}, {
unwrapper: buildUnwrapper('Decrement'),
handler: state => state - 1
}], 0);

let state = undefined;
state = reducer(state, { type: 'Increment' });
state = reducer(state, { type: 'Increment' });
state = reducer(state, { type: 'Increment' });
state = reducer(state, { type: 'Decrement' });

console.log(state); // 2
```

0 comments on commit 98c3ffe

Please sign in to comment.