UNPKG

redux-modular

Version:
25 lines (20 loc) 705 B
import createAction from './create-action' const isArray = value => { return typeof value === 'object' && value !== null && value.constructor === Array } const isString = value => typeof value === 'string' export default function globalizeActions (pathToState, actions) { if (isArray(pathToState)) { pathToState = pathToState.join('.') } else if (pathToState !== null && !isString(pathToState)) { throw new Error('path must be a string or array') } return Object.keys(actions).reduce((prev, key) => { const type = pathToState ? `${key} (${pathToState})` : key return Object.assign({}, prev, { [key]: createAction(type, actions[key]) }) }, {}) }