Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the option to not call the reducer upon recycle #7

Merged
merged 5 commits into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.DS_Store
lib
coverage
.idea
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
Loading