UNPKG

jperl-redux-recycle

Version:

higher-order reducer to reset the redux state on certain actions

23 lines (20 loc) 662 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = recycleState; // redux-recycle higher order reducer function recycleState(reducer) { var actions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var initialState = arguments[2]; var getInitialState = typeof initialState === 'function' ? initialState : function () { return initialState; }; return function (state, action) { if (actions.indexOf(action.type) >= 0) { return reducer(getInitialState(state, action), { type: '@@redux-recycle/INIT' }); } return reducer(state, action); }; } // /redux-recycle