Skip to content

Commit

Permalink
improved readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vzaidman committed Jul 9, 2017
1 parent 06d2341 commit 998f3b1
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,47 @@ _higher-order reducer to reset the redux state on certain actions_
npm install --save redux-recycle
```

## Resetting state

`redux-recycle` is a reducer enhancer (higher-order reducer), it provides the
`recycleState` function, which takes an existing reducer and an array of
actions that will reset the state.

Optionally, you can also pass an initial
state to reset to.

Optionally, you can also pass a config object.

It currently recieves one config: `recycleActionType` that defaults to `@@redux-recycle/INIT`.
If recycleActionType is provided, the reducer function will be called with `initialState` and the provided action name.
Otherwise, the state will be reset without calling the reducer one more time.

## API

```js
import recycleState from 'redux-recycle';

//Recycle the state on the following list of actions
recycleState(reducer, [ARRAY_OF_ACTIONS])

//Also provide the state to reset to
recycleState(reducer, [ARRAY_OF_ACTIONS], initialState)

//Also provide the state to reset to, based on the state and action passed
recycleState(reducer, [ARRAY_OF_ACTIONS], (state, action) => initialState)
```

//Also provides the name of the action that will be called on the reducer when recycling it
recycleState(reducer, [ARRAY_OF_ACTIONS], (state, action) => initialState, {
recycleActionType: '@@redux-recycle/MY_OWN_ACTION_NAME'
})

## Resetting state
//Recycles the state to initialState without calling the reducer with any action
recycleState(reducer, [ARRAY_OF_ACTIONS], initialState, {
recycleActionType: false
})
```

`redux-recycle` is a reducer enhancer (higher-order reducer), it provides the
`recycleState` function, which takes an existing reducer and an array of
actions that will reset the state. Optionally, you can also pass an initial
state to reset to. (defaults to calling your reducer with
`@@redux-recycle/INIT` and an `undefined` state, which will have the same effect
as the initial redux action)
## Instructions

Firstly, import `redux-recycle`:

Expand Down

0 comments on commit 998f3b1

Please sign in to comment.