Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkis committed Feb 21, 2017
1 parent 9cc0f62 commit 41c0a27
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,24 @@ const RootComponent = () => (

Obviously the code snippet above is responsible for rendering two independent instances of `Counter`, utilizng Action wrapping and selectors.

## Action Unwrapping
## Action Unwrapping

OK, there is the other side of the coin which is called Action Unwrapping. All the actions are already wrapped and using selectors we assume that our state is isolated, but now we need to be able to unwrap the action in reducer and mutate corresponding state slice. There's another helper function called [`buildReducer`](./api/buildReducer.md) for building a reducer which can handle wrapped actions.

`buildReducer` function accepts a list of `UnwrapperHandlerPair` the pair is actually an object containing two keys: `unwrapper` and `handler`.

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

// UnwrapperHandlerPair is just a plain old JavaScript object
// prism provides a helper function to build simple unwrapper
const unwrapperHandlerPair = {
unwrapper: buildUnwrapper('Increment'),
handler: (state, action) => state + 1
};
```

`Unwrapper` is responsible for matching the action and when the action is matched it can potentially unwrap it as well. For example `buildUnwrapper('Increment')` creates an unwrapper which matches either action starting with `Increment.` prefix and then it provides unwrapped action to `handler` function, or it matches action `Increment` directly therefore no action is unwrappped and original `Increment` action is passed to the handler.



0 comments on commit 41c0a27

Please sign in to comment.