<commit_before>import React from 'react';
import _ from 'lodash';
import Immutable from 'immutable';

var Input = (ComposedComponent) => class extends React.Component {

  /**
   * Define property types
   */
  static propTypes = {
    name: React.PropTypes.string.isRequired
  }

  static contextTypes = {
    form: React.PropTypes.object
  }

  static defaultProps = ComposedComponent.defaultProps

  /**
   * Determines if the component should re-render
   */
  shouldComponentUpdate = (nextProps, nextState) => {
    var { value, ...otherProps } = this.props;
    var previous = value;
    var { value, ...otherNextProps } = nextProps;

    if (!Immutable.is(previous, value) ||
        !_.isEqual(otherProps, otherNextProps) ||
        !_.isEqual(this.state, nextState)) {
      return true;
    }

    return false;
  }

  generateFormName = () => {
    if (this.props.name.charAt(0) === "[") {
      return this.context.form.model + this.props.name;
    } else {
      return this.context.form.model + "[" + this.props.name + "]";
    }
  }

  /**
   * Returns modified properties for the input element.
   *
   * @method inputProps
   */
  inputProps = () => {
    var { ...inputProps } = this.props;

    inputProps.name = this.generateFormName();

    // set id so label will work correctly
    inputProps.id = inputProps.name;

    if (inputProps.onChange) {
      inputProps.onChange = this.handleOnChange;
    }

    return inputProps;
  }

  /**
   * Calls the onChange method with relevant data.<commit_msg>inputs no longer require forms<commit_after>import React from 'react';
import _ from 'lodash';
import Immutable from 'immutable';

var Input = (ComposedComponent) => class extends React.Component {

  /**
   * Define property types
   */
  static propTypes = {
    name: React.PropTypes.string.isRequired
  }

  static contextTypes = {
    form: React.PropTypes.object
  }

  static defaultProps = ComposedComponent.defaultProps

  /**
   * Determines if the component should re-render
   */
  shouldComponentUpdate = (nextProps, nextState) => {
    var { value, ...otherProps } = this.props;
    var previous = value;
    var { value, ...otherNextProps } = nextProps;

    if (!Immutable.is(previous, value) ||
        !_.isEqual(otherProps, otherNextProps) ||
        !_.isEqual(this.state, nextState)) {
      return true;
    }

    return false;
  }

  generateFormName = () => {
    if (this.context.form) {
      if (this.props.name.charAt(0) === "[") {
        return this.context.form.model + this.props.name;
      } else {
        return this.context.form.model + "[" + this.props.name + "]";
      }
    } else {
      return this.props.name;
    }
  }

  /**
   * Returns modified properties for the input element.
   *
   * @method inputProps
   */
  inputProps = () => {
    var { ...inputProps } = this.props;

    inputProps.name = this.generateFormName();

    // set id so label will work correctly
    inputProps.id = inputProps.name;

    if (inputProps.onChange) {
      inputProps.onChange = this.handleOnChange;
    }

    return inputProps;
  }

  /**
   * Calls the onChange method with relevant data.
{'fraction_non_alphanumeric': 0.12924738012067322, 'fraction_numerical': 0.0006351222610352493, 'mean_word_length': 2.595890410958904, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7453644', 'n_tokens_mistral': 980, 'n_tokens_neox': 953, 'n_words': 226}