UNPKG

redux-contexts

Version:

[![NPM Version](https://img.shields.io/npm/v/redux-contexts.svg?style=flat-square)](https://www.npmjs.com/package/multireducer) [![Build status](https://img.shields.io/travis/Vinnovera/redux-contexts/master.svg?style=flat-square)](https://travis-ci.org/Vi

20 lines (17 loc) 683 B
import { wrapAction } from 'multireducer'; import virtualizedState from './virtualizedState'; export default (dispatch, contextName) => { const wrappedDispatch = (action) => { let wrappedAction; if (typeof action === 'function') { wrappedAction = (dispatch, getState, extraArgument) => { const wrappedGetState = () => virtualizedState(getState(), contextName); return action(wrappedDispatch, wrappedGetState, { ...extraArgument, dispatch, getState, contextName }); } } else if (typeof action === 'object') { wrappedAction = wrapAction(action, contextName); } return dispatch(wrappedAction); }; return wrappedDispatch; };