UNPKG

async-connect

Version:

HOC for calling and statusing redux actions on componentDidMount

30 lines (23 loc) 779 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function (depsMapper) { var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (!props.store) { throw new Error('async-connect requires a redux store'); } var state = props.store.getState(); var deps = typeof depsMapper === 'function' ? depsMapper(props) : depsMapper; if (!Array.isArray(deps)) { throw new Error('async-connect requires an array of actions.'); } if (!state.async || !state.async.statuses) { throw new Error('async-connect requires an async reducer.'); } deps.forEach(function (dep) { if (!state.async.statuses[dep.type]) { props.store.dispatch(dep.action(dep.payload)); } }); };