<commit_before>import React from "react";
import Glamorous from "glamorous";
import PropTypes from "prop-types";

export default class DebounceInput extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      debounceTimeout: null,
      input: props.initialInput
    };
    this.handleInputChange = this.handleInputChange.bind(this);
  }
  static propTypes = {
    inputHandler: PropTypes.func.isRequired,
    inputHandlerArgs: PropTypes.array,
    initialInput: PropTypes.any,
    debounce: PropTypes.number.isRequired,
    type: PropTypes.string.isRequired,
    size: PropTypes.number
  };
  handleInputChange(event) {
    const newInput = event.target.value;
    this.setState(prevState => {
      if (prevState.debounceTimeout) {
        clearTimeout(prevState.debounceTimeout);
      }
      const newTimeout = setTimeout(() => {
        this.props.inputHandler(newInput, this.props.inputHandlerArgs);
      }, this.props.debounce);
      return { input: newInput, debounceTimeout: newTimeout };
    });
  }
  render() {
    return (
      <input
        type={this.props.type}
        size={this.props.size}
        onChange={this.handleInputChange}
        value={this.state.input}
      />
    );
  }
}<commit_msg>Clear debounce timeout on unmount (#18)<commit_after>import React from "react";
import Glamorous from "glamorous";
import PropTypes from "prop-types";

export default class DebounceInput extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      debounceTimeout: null,
      input: props.initialInput
    };
    this.handleInputChange = this.handleInputChange.bind(this);
  }
  static propTypes = {
    inputHandler: PropTypes.func.isRequired,
    inputHandlerArgs: PropTypes.array,
    initialInput: PropTypes.any,
    debounce: PropTypes.number.isRequired,
    type: PropTypes.string.isRequired,
    size: PropTypes.number
  };
  componentWillUnmount() {
    if (this.state.debounceTimeout) {
      clearTimeout(this.state.debounceTimeout);
    }
  }
  handleInputChange(event) {
    const newInput = event.target.value;
    this.setState(prevState => {
      if (prevState.debounceTimeout) {
        clearTimeout(prevState.debounceTimeout);
      }
      const newTimeout = setTimeout(() => {
        this.props.inputHandler(newInput, this.props.inputHandlerArgs);
      }, this.props.debounce);
      return { input: newInput, debounceTimeout: newTimeout };
    });
  }
  render() {
    return (
      <input
        type={this.props.type}
        size={this.props.size}
        onChange={this.handleInputChange}
        value={this.state.input}
      />
    );
  }
}
{'fraction_non_alphanumeric': 0.11508085746521249, 'fraction_numerical': 0.000752162467092892, 'mean_word_length': 3.0548780487804876, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3191255', 'n_tokens_mistral': 784, 'n_tokens_neox': 791, 'n_words': 143}