reduce-redux
Version:
A helper library to reduce redux boilerplate and make developers life easier.
25 lines (17 loc) • 537 B
JavaScript
const isPlainObject = require('lodash.isplainobject')
require('es6-object-assign').polyfill();
exports.createReducer = function(initialState, actionsMap) {
return function(prevState, action) {
if (!prevState) {
return initialState
}
if (!actionsMap.hasOwnProperty(action.type)) {
return prevState
}
var result = actionsMap[action.type](action, prevState)
if (isPlainObject(result) && isPlainObject(prevState)) {
return Object.assign({}, prevState, result)
}
return result
}
}