all files / src/ createReduxForm.js

100% Statements 48/48
100% Branches 27/27
100% Functions 12/12
100% Lines 15/15
9 statements, 1 function, 12 branches Ignored     
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           54× 54× 54× 54×               54×     54×       54×       56×           54×          
import createReduxFormConnector from './createReduxFormConnector';
import hoistStatics from 'hoist-non-react-statics';
 
/**
 * The decorator that is the main API to redux-form
 */
const createReduxForm =
  (isReactNative, React, connect) => {
    const {Component} = React;
    const reduxFormConnector = createReduxFormConnector(isReactNative, React, connect);
    return (config, mapStateToProps, mapDispatchToProps, mergeProps, options) =>
      WrappedComponent => {
        const ReduxFormConnector = reduxFormConnector(WrappedComponent, mapStateToProps, mapDispatchToProps, mergeProps, options);
        const configWithDefaults = {
          overwriteOnInitialValuesChange: true,
          touchOnBlur: true,
          touchOnChange: false,
          destroyOnUnmount: true,
          ...config
        };
        class ConnectedForm extends Component {
          constructor(props) {
            super(props);
 
            this.handleSubmitPassback = this.handleSubmitPassback.bind(this);
          }
 
          handleSubmitPassback(submit) {
            this.submit = submit;
          }
 
          render() {
            return (<ReduxFormConnector
              {...configWithDefaults}
              {...this.props}
              submitPassback={this.handleSubmitPassback}/>);
          }
        }
        return hoistStatics(ConnectedForm, WrappedComponent);
      };
  };
 
export default createReduxForm;