Skip to content

Commit

Permalink
1.1.0: pass initialState to reducer (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
omnidan committed Feb 20, 2016
1 parent 1028d85 commit 14673c0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-recycle",
"version": "1.0.0",
"version": "1.1.0",
"description": "higher-order reducer to reset the redux state on certain actions",
"main": "lib/index.js",
"scripts": {
Expand Down
5 changes: 1 addition & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
export default function recycleState (reducer, actions = [], initialState) {
return (state, action) => {
if (actions.indexOf(action.type) >= 0) {
if (initialState === undefined) {
return reducer(undefined, { type: '@@redux-recycle/INIT' })
}
return initialState
return reducer(initialState, { type: '@@redux-recycle/INIT' })
}
return reducer(state, action)
}
Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('recycleState', () => {

it('custom initial state', () => {
let recycleableReducer = recycleState(reducer, ['RECYCLE'], 'CUSTOM_INITIAL_STATE')
expect(recycleableReducer('A', { type: 'RECYCLE' })).to.deep.equal('CUSTOM_INITIAL_STATE')
expect(recycleableReducer('A', { type: 'RECYCLE' })).to.deep.equal({ state: 'CUSTOM_INITIAL_STATE', type: '@@redux-recycle/INIT' })
})

it('a non-recycle action', () => {
Expand Down

0 comments on commit 14673c0

Please sign in to comment.