All files connect.js

100% Statements 10/10
100% Branches 1/1
100% Functions 5/5
100% Lines 10/10
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                                      22x 22x     27x     22x 22x       22x 22x 22x   22x 22x          
/**
* Copyright 2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
 
import { connect } from 'react-redux';
import createRef from 'create-react-ref/lib/createRef';
 
import { storeKey } from './storeOptions';
 
import React, { PureComponent } from 'react';
 
// just inject the position store and further magic
function withPositionConsumer(Component) {
  class MSAPositionConsumer extends PureComponent {
    constructor(props) {
      super(props);
      this.el = createRef();
    }
    render() {
      return <Component ref={this.el} {...this.props} />
    }
  }
  MSAPositionConsumer.displayName = Component.name + '-PositionStore';
  return MSAPositionConsumer;
}
 
function msaConnect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
  options.storeKey = storeKey;
  const reduxConnect = connect(mapStateToProps, mapDispatchToProps, mergeProps, options);
  return function(Component) {
    //console.log(Component);
    const wrappedComponent = withPositionConsumer(Component);
    return reduxConnect(wrappedComponent);
  }
}
 
export default msaConnect;