redux-recycle
Version:
higher-order reducer to reset the redux state on certain actions
28 lines (23 loc) • 855 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = recycleState;
// redux-recycle higher order reducer
function recycleState(reducer, actions, initialState) {
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var getInitialState = typeof initialState === 'function' ? initialState : function () {
return initialState;
};
var recycleActionType = typeof config.recycleActionType === 'undefined' ? '@@redux-recycle/INIT' : config.recycleActionType;
return function (state, action) {
if (actions.indexOf(action.type) === -1) {
return reducer(state, action);
}
if (recycleActionType) {
return reducer(getInitialState(state, action), { type: recycleActionType });
}
return getInitialState(state, action);
};
}
// /redux-recycle