All files / core UnbxdConnect.js

23.53% Statements 4/17
0% Branches 0/4
33.33% Functions 2/6
20% Lines 3/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45      2x                                                                 2x     2x          
import React from 'react';
import PropTypes from 'proptypes';
 
const UnbxdConnect = (mapStateToProps, mapDispatchToProps) => (WrappedComponent) => {
  class ContainerComponent extends React.Component {
    componentDidMount() {
      const { store } = this.context;
      this.unsubscribe = store.subscribe(() => this.forceUpdate());
    }
 
    componentWillUnmount() {
      this.unsubscribe();
    }
 
    render() {
      const { store } = this.context;
      let stateProps = {};
      if (typeof mapStateToProps === 'function') {
        stateProps = mapStateToProps(store.getState());
      }
      let dispatchProps = {};
      if (typeof mapDispatchToProps === 'function') {
        dispatchProps = mapDispatchToProps(store.dispatch());
      }
      const props = Object.assign(
        {},
        this.props,
        stateProps,
        dispatchProps,
        { dispatch: store.dispatch },
        { getState: store.getState },
      );
      return <WrappedComponent {...props} />;
    }
  }
 
  ContainerComponent.contextTypes = {
    store: PropTypes.object,
  };
  return ContainerComponent;
};
 
 
export default UnbxdConnect;