<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';

import ActionTypes from './ActionTypes';
import { fetchPost } from './sagas';

export default function repressConnect ({
  /** The Wordpress post type that the component represents. */
  postType = 'post',
  /** From which property on the component's props will the route parameters be derived? */
  routeParamsPropName = 'params',
  /** Will the request to WP-API be made with the `_embed` query parameter? */
  useEmbedRequestQuery = true,
  /** Object to merge with the action that is dispatched in order to request post data. */
  fetchDataOptions = {},
  /** The collection name for the redux store where items of type `postType` are placed. */
  postTypePlural
} = {}) {
  return (target) => {
    if (target.__repress) {
      throw new Error(`The component "${target.name}" is already wrapped by Repress.`);
    }

    const postTypePlural = postTypePlural || postType + 's';

    const mapStateToProps = (state, ownProps) => {
      const params = ownProps[routeParamsPropName];
      const collection = state.repress[postTypePlural];

      return collection
          ? { [postType]: collection[postTypePlural][params.id] }
          : { [postType]: null };
    };

    class RepressComponentWrapper extends Component {
      constructor (props, context) {
        super(props, context);
        this.props.dispatch({
          type: ActionTypes.REQUEST_POST,
          params: this.props[routeParamsPropName],
          options: { postType, useEmbedRequestQuery, fetchDataOptions }
        });
      }

      render () {
        return <target {...this.props} __repress={true} />;
      }
    }

    RepressComponentWrapper.__repress = true;

    RepressComponentWrapper.fetchData = () => [fetchPost, {
      postType: target.name,
      ...fetchDataOptions
    }];

    return connect(mapStateToProps)(RepressComponentWrapper);
  };<commit_msg>Move dispatch out of constructor;<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';

import ActionTypes from './ActionTypes';
import { fetchPost } from './sagas';

export default function repressConnect ({
  /** The Wordpress post type that the component represents. */
  postType = 'post',
  /** From which property on the component's props will the route parameters be derived? */
  routeParamsPropName = 'params',
  /** Will the request to WP-API be made with the `_embed` query parameter? */
  useEmbedRequestQuery = true,
  /** Object to merge with the action that is dispatched in order to request post data. */
  fetchDataOptions = {},
  /** The collection name for the redux store where items of type `postType` are placed. */
  postTypePlural
} = {}) {
  return (target) => {
    if (target.__repress) {
      throw new Error(`The component "${target.name}" is already wrapped by Repress.`);
    }

    const postTypePlural = postTypePlural || postType + 's';

    const mapStateToProps = (state, ownProps) => {
      const params = ownProps[routeParamsPropName];
      const collection = state.repress[postTypePlural];

      return collection
          ? { [postType]: collection[postTypePlural][params.id] }
          : { [postType]: null };
    };

    class RepressComponentWrapper extends Component {
      componentWillMount () {
        this.props.dispatch({
          type: ActionTypes.REQUEST_POST,
          params: this.props[routeParamsPropName],
          options: { postType, useEmbedRequestQuery, fetchDataOptions }
        });
      }

      render () {
        return <target {...this.props} __repress={true} />;
      }
    }

    RepressComponentWrapper.__repress = true;

    RepressComponentWrapper.fetchData = () => [fetchPost, {
      postType: target.name,
      ...fetchDataOptions
    }];

    return connect(mapStateToProps)(RepressComponentWrapper);
  };
{'fraction_non_alphanumeric': 0.11516709511568124, 'fraction_numerical': 0.0, 'mean_word_length': 3.08718487394958, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1723293', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1046, 'n_words': 316}