All files / src/domain/connect index.js

100% Statements 6/6
100% Branches 4/4
100% Functions 3/3
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27              9x     3x 3x     3x       3x     3x          
import { connect as originalConnect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { routerActions } from 'react-router-redux';
import { createBuildRoute } from 'domain/createBuildRoute';
import is from 'is_js';
 
export function connect(mapStateToProps, mapDispatchToProps, mergeProps, options) {
  return originalConnect(wrapMapStateToProps, wrapMapDispatchToProps, mergeProps, options);
 
  function wrapMapStateToProps(state, ownProps) {
    const buildRoute = createBuildRoute(ownProps);
    const stateToProps = is.function(mapStateToProps) ?
        mapStateToProps(state, ownProps) :
        undefined;
    return Object.assign({ buildRoute }, stateToProps);
  }
 
  function wrapMapDispatchToProps(dispatch, ownProps) {
    const dispatchToProps = is.function(mapDispatchToProps) ?
        mapDispatchToProps(dispatch, ownProps) :
        undefined;
    return Object.assign({}, bindActionCreators(routerActions, dispatch), dispatchToProps);
  }
}
 
export default connect;