diff --git a/package.json b/package.json index 263d052..89cbccc 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/index.js b/src/index.js index bf81a8b..d30ee15 100644 --- a/src/index.js +++ b/src/index.js @@ -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) } diff --git a/test/index.spec.js b/test/index.spec.js index 0463bc7..7a62b5c 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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', () => {