<commit_before>import React from 'react';


export default React.createClass({
  fields: {},
  invalidFields: {},

  getInitialState() {
    return {valid: true};
  },

  getDefaultProps() {
    return {values: {}};
  },

  validate() {
    return new Promise((resolve) => {
      this.invalidFields = {};
      for (let fieldName in this.fields) {
        let field = this.fields[fieldName];
        if (!field.validate()) {
          this.invalidFields[fieldName] = field;
        }
      }
      let valid = Object.keys(this.invalidFields).length === 0;
      this.setState({valid: valid}, resolve);
    });
  },

  handleSubmit(e) {
    e.preventDefault();
    this.validate()
      .then(() => {
        if (this.props.onSubmit) {
          this.props.onSubmit(e, {
            valid: this.state.valid,
            values: this.values()
          });
        }
      });
  },

  values() {
    let values = {};
    for (let fieldName in this.fields) {
      let field = this.fields[fieldName];
      values[fieldName] = field.state.value
    }
    return values;
  },

  addPropsToChildren(children, props) {
    return React.Children.map(children, (child) => {
      let childProps = {};
      if (child.props) {
        childProps.children = this.addPropsToChildren(child.props.children, props);
        if (child.type.displayName === "Field") {
          const initialValues = this.props.values[child.props.name] || {};
          childProps = Object.assign(childProps, initialValues, props);
        }
        return React.cloneElement(child, childProps);
      }
      return child;
    });
  },

  children() {
    let fields = {}
    const ref = {ref: (field) => { if (field) { fields[field.props.name] = field;} }}
    const children = this.addPropsToChildren(this.props.children, ref);
    this.fields = fields;<commit_msg>Remove unnecessary variable<commit_after>import React from 'react';


export default React.createClass({
  fields: {},
  invalidFields: {},

  getInitialState() {
    return {valid: true};
  },

  getDefaultProps() {
    return {values: {}};
  },

  validate() {
    return new Promise((resolve) => {
      this.invalidFields = {};
      for (let fieldName in this.fields) {
        let field = this.fields[fieldName];
        if (!field.validate()) {
          this.invalidFields[fieldName] = field;
        }
      }
      let valid = Object.keys(this.invalidFields).length === 0;
      this.setState({valid: valid}, resolve);
    });
  },

  handleSubmit(e) {
    e.preventDefault();
    this.validate()
      .then(() => {
        if (this.props.onSubmit) {
          this.props.onSubmit(e, {
            valid: this.state.valid,
            values: this.values()
          });
        }
      });
  },

  values() {
    let values = {};
    for (let fieldName in this.fields) {
      values[fieldName] = this.fields[fieldName].state.value
    }
    return values;
  },

  addPropsToChildren(children, props) {
    return React.Children.map(children, (child) => {
      let childProps = {};
      if (child.props) {
        childProps.children = this.addPropsToChildren(child.props.children, props);
        if (child.type.displayName === "Field") {
          const initialValues = this.props.values[child.props.name] || {};
          childProps = Object.assign(childProps, initialValues, props);
        }
        return React.cloneElement(child, childProps);
      }
      return child;
    });
  },

  children() {
    let fields = {}
    const ref = {ref: (field) => { if (field) { fields[field.props.name] = field;} }}
    const children = this.addPropsToChildren(this.props.children, ref);
    this.fields = fields;
{'fraction_non_alphanumeric': 0.1496858781753619, 'fraction_numerical': 0.0005462988254575252, 'mean_word_length': 2.362718089990817, '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': '7609399', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1080, 'n_words': 218}