<commit_before>import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import momentPropTypes from 'react-moment-proptypes';
import moment from 'moment';
import { STOPKY_ONE_TICK } from '../../constants';
import Displej from './Displej';

class RunningDisplej extends PureComponent {
  state = { current: new Date() };

  componentDidMount = () => {
    if (this.props.running) {
      this.timerID = setInterval(() => this.tick(), STOPKY_ONE_TICK);
    }
  };

  componentWillUnmount = () => {
    this.stopTimer();
  };

  stopTimer = () => {
    clearInterval(this.timerID);
    this.timerID = null;
  };

  tick = () => {
    this.setState({ current: new Date() });
  };

  startTimer = () => {
    this.timerID = setInterval(() => this.tick(), STOPKY_ONE_TICK);
  };

  render = () => {
    const { base, delta, running } = this.props;

    const duration = running
      ? moment.duration(this.state.current.getTime() - base.getTime())
      : delta;
    return <Displej duration={duration} />;
  };
}

RunningDisplej.propTypes = {<commit_msg>Add componentDidUpdate() lifecycle method to RunningDisplej.<commit_after>import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import momentPropTypes from 'react-moment-proptypes';
import moment from 'moment';
import { STOPKY_ONE_TICK } from '../../constants';
import Displej from './Displej';

class RunningDisplej extends PureComponent {
  state = { current: new Date() };

  componentDidMount = () => {
    if (this.props.running) {
      this.startTimer();
    } else {
      this.stopTimer();
    }
  };

  componentDidUpdate = prevProps => {
    if (this.props.running && !prevProps.running) {
      this.startTimer();
    } else if (!this.props.running && prevProps.running) {
      this.stopTimer();
    }
  };

  componentWillUnmount = () => {
    this.stopTimer();
  };

  stopTimer = () => {
    clearInterval(this.timerID);
    this.timerID = null;
  };

  tick = () => {
    this.setState({ current: new Date() });
  };

  startTimer = () => {
    this.timerID = setInterval(() => this.tick(), STOPKY_ONE_TICK);
  };

  render = () => {
    const { base, delta, running } = this.props;

    const duration = running
      ? moment.duration(this.state.current.getTime() - base.getTime())
      : delta;
    return <Displej duration={duration} />;
  };
}

RunningDisplej.propTypes = {
{'fraction_non_alphanumeric': 0.16340141725719048, 'fraction_numerical': 0.0, 'mean_word_length': 3.1666666666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2968111', 'n_tokens_mistral': 777, 'n_tokens_neox': 762, 'n_words': 159}