<commit_before>// @flow
import {map} from 'lodash';
import PropTypes from 'prop-types';
import {Component, createElement} from 'react';
import {bindActionCreators, type Dispatch} from 'redux';
import {
  connect as reactReduxConnect,
  type MapStateToProps,
  type StatelessComponent,
} from 'react-redux';

import type {Action, ReduxModule} from '@wtg/redux-modules';

export default function connectComponent<S: Object, OP: Object, SP: Object>(
  selector: MapStateToProps<S, OP, SP>,
  modules: Array<ReduxModule<Object, any, any>>,
) {
  const actionCreators = Object.assign({}, ...map(modules, 'actionCreators'));
  type DP = typeof actionCreators;
  type P = $Supertype<OP & SP & DP>;
  const mapDispatchToProps = (dispatch: Dispatch<Action<any, any>>) =>
    bindActionCreators(actionCreators, dispatch);
  const reactReduxConnectComponent = reactReduxConnect(
    selector,
    mapDispatchToProps,
  );
  return <Def, St>(
    component: StatelessComponent<P> | Class<React$Component<Def, P, St>>,
  ) => {
    class Connect extends Component {
      static contextTypes = {
        registerModules: PropTypes.func,
      };

      constructor(props, context) {
        super(props, context);
        if (context.registerModules) {
          context.registerModules(modules);
        }
      }

      render() {
        return createElement(component, this.props);
      }
    }

    return reactReduxConnectComponent(Connect);
  };
}<commit_msg>[@wtg/react-redux-modules] Prevent empty initial render.<commit_after>// @flow
import {map} from 'lodash';
import PropTypes from 'prop-types';
import {Component, createElement} from 'react';
import {bindActionCreators, type Dispatch} from 'redux';
import {
  connect as reactReduxConnect,
  type MapStateToProps,
  type StatelessComponent,
} from 'react-redux';

import type {Action, ReduxModule} from '@wtg/redux-modules';

export default function connectComponent<S: Object, OP: Object, SP: Object>(
  selector: MapStateToProps<S, OP, SP>,
  modules: Array<ReduxModule<Object, any, any>>,
) {
  const actionCreators = Object.assign({}, ...map(modules, 'actionCreators'));
  type DP = typeof actionCreators;
  type P = $Supertype<OP & SP & DP>;
  const mapDispatchToProps = (dispatch: Dispatch<Action<any, any>>) =>
    bindActionCreators(actionCreators, dispatch);
  const reactReduxConnectComponent = reactReduxConnect(
    selector,
    mapDispatchToProps,
  );
  return <Def, St>(
    component: StatelessComponent<P> | Class<React$Component<Def, P, St>>,
  ) => {
    const connectedComponent = reactReduxConnectComponent(component);
    return class Connect extends Component {
      static contextTypes = {
        registerModules: PropTypes.func,
      };

      constructor(props, context) {
        super(props, context);
        if (context.registerModules) {
          context.registerModules(modules);
        }
      }

      render() {
        return createElement(connectedComponent, this.props);
      }
    };
  };
}
{'fraction_non_alphanumeric': 0.1214452994312479, 'fraction_numerical': 0.0, 'mean_word_length': 3.909688013136289, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3013687', 'n_tokens_mistral': 882, 'n_tokens_neox': 880, 'n_words': 224}