<commit_before>/* @flow */
import React, {Component, PropTypes } from 'react';
import NumberEditor from 'react-number-editor';

export default class DebouncedNumberEditor extends Component {
  constructor(props: any){
    super(props);
    this.state = { value: props.value, debouncing: false };
    this.onLocalValueChange = this.onLocalValueChange.bind(this);
  }

  // $FlowIssue
  static propTypes = {
      onValueChange: PropTypes.func.isRequired,
      value: PropTypes.number.isRequired,
      min: PropTypes.number.isRequired,
      max: PropTypes.number.isRequired,
      label: PropTypes.string.isRequired,
      step: PropTypes.number.isRequired,
  };

  componentWillReceiveProps(nextProps: any) {
    if (nextProps.value !== this.props.value) this.setState({value: nextProps.value});
  };

  onLocalValueChange(val: string) {
    const newValue = parseInt(val);
    const {min, max} = this.props;
    if (newValue === this.state.value) return;
    if (newValue < min) return;
    if (newValue > max) return;
    this.setState({value: newValue});
    if (this.state.debouncing) return;
    this.setState({debouncing: true});
    setTimeout(() => {
      this.props.onValueChange(this.state.value);
      this.setState({debouncing: false})
    }, 100);
  }

  render(): any {
    const { onValueChange, min, max, label, step } = this.props;
    return (<NumberEditor
              step={step}
              onValueChange={this.onLocalValueChange}
              value={this.state.value}
              min={min}
              max={max}
              style={{width: "2.5em"}}
              label={label}
           />);
  }

}<commit_msg>Add decimals property to debounced number editor<commit_after>/* @flow */
import React, {Component, PropTypes } from 'react';
import NumberEditor from 'react-number-editor';

export default class DebouncedNumberEditor extends Component {
  constructor(props: any){
    super(props);
    this.state = { value: props.value, debouncing: false };
    this.onLocalValueChange = this.onLocalValueChange.bind(this);
  }

  // $FlowIssue
  static propTypes = {
      onValueChange: PropTypes.func.isRequired,
      value: PropTypes.number.isRequired,
      min: PropTypes.number.isRequired,
      max: PropTypes.number.isRequired,
      label: PropTypes.string.isRequired,
      step: PropTypes.number.isRequired,
      decimals: PropTypes.number
  };

  componentWillReceiveProps(nextProps: any) {
    if (nextProps.value !== this.props.value) this.setState({value: nextProps.value});
  };

  onLocalValueChange(val: string) {
    const newValue = parseFloat(val);
    const {min, max} = this.props;
    if (newValue === this.state.value) return;
    if (newValue < min) return;
    if (newValue > max) return;
    this.setState({value: newValue});
    if (this.state.debouncing) return;
    this.setState({debouncing: true});
    setTimeout(() => {
      this.props.onValueChange(this.state.value);
      this.setState({debouncing: false})
    }, 100);
  }

  render(): any {
    const { decimals, onValueChange, min, max, label, step } = this.props;
    return (<NumberEditor
              step={step}
              onValueChange={this.onLocalValueChange}
              value={this.state.value}
              min={min}
              max={max}
              style={{width: "2.5em"}}
              label={label}
              decimals={decimals}
           />);
  }

}
{'fraction_non_alphanumeric': 0.13204225352112675, 'fraction_numerical': 0.0029342723004694834, 'mean_word_length': 2.838963963963964, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1997023', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1017, 'n_words': 214}