<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import Style from './utils/style';
import Rating from './Rating';
import noop from './utils/noop';

class RatingAPILayer extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      value: props.initialRating
    };
    this.handleClick = this.handleClick.bind(this);
    this.handleHover = this.handleHover.bind(this);
  }

  componentWillReceiveProps(nextProps) {
    this.setState({
      value: nextProps.initialRating
    });
  }

  componentDidUpdate(prevProps, prevState) {
    // If we have a new value trigger onChange callback
    if (this.state.value !== prevState.value) {
      this.props.onChange(this.state.value);
    }
  }

  handleClick(value, e) {
    const newValue = this.translateDisplayValueToValue(value);
    // Avoid calling setState if not necessary. Micro optimisation.
    if (this.state.value !== newValue) {
      this.setState({
        value: newValue
      });
    }
  }

  handleHover(displayValue) {
    const value = displayValue === undefined
      ? displayValue
      : this.translateDisplayValueToValue(displayValue);
    this.props.onHover(value);
  }

  translateDisplayValueToValue(displayValue) {
    const translatedValue = displayValue * this.props.step + this.props.start;
    // minimum value cannot be equal to start, since it's exclusive
    return translatedValue === this.props.start
      ? translatedValue + 1 / this.props.fractions
      : translatedValue;
  }

  tranlateValueToDisplayValue(value) {
    if (value === undefined) {<commit_msg>Fire `onChange` when state is changed by a click event<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import Style from './utils/style';
import Rating from './Rating';
import noop from './utils/noop';

class RatingAPILayer extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      value: props.initialRating
    };
    this.handleClick = this.handleClick.bind(this);
    this.handleHover = this.handleHover.bind(this);
  }

  componentWillReceiveProps(nextProps) {
    this.setState({
      value: nextProps.initialRating
    });
  }

  handleClick(value, e) {
    const newValue = this.translateDisplayValueToValue(value);
    // Avoid calling setState if not necessary. Micro optimisation.
    if (this.state.value !== newValue) {
      // If we have a new value trigger onChange callback.
      this.setState({
        value: newValue
      }, () => this.props.onChange(this.state.value));
    }
  }

  handleHover(displayValue) {
    const value = displayValue === undefined
      ? displayValue
      : this.translateDisplayValueToValue(displayValue);
    this.props.onHover(value);
  }

  translateDisplayValueToValue(displayValue) {
    const translatedValue = displayValue * this.props.step + this.props.start;
    // minimum value cannot be equal to start, since it's exclusive
    return translatedValue === this.props.start
      ? translatedValue + 1 / this.props.fractions
      : translatedValue;
  }

  tranlateValueToDisplayValue(value) {
    if (value === undefined) {
{'fraction_non_alphanumeric': 0.11061946902654868, 'fraction_numerical': 0.0006321112515802782, 'mean_word_length': 3.306122448979592, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6681803', 'n_tokens_mistral': 922, 'n_tokens_neox': 902, 'n_words': 218}