<commit_before>import React, { PropTypes } from 'react';
import classNames from 'classnames';
import interact from 'interact.js';
import isEmpty from 'lodash/isEmpty';
import { CommonPropTypes, PureComponent } from '../../../utils';

import Ticks from './ticks';
import { getSnapTargetFunc } from './util';
import style from './style.css';

export default class Track extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {};
    this.trackRef = this.trackRef.bind(this);
  }

  componentWillReceiveProps(newProps) {
    const state = {};

    if (this.props.snapTarget !== newProps.snapTarget) {
      this.bindInteract(newProps.snapTarget);

      if (newProps.ticks) {
        state.ticks = [];
        for (let x = newProps.snapTarget.x; x < this.width; x += newProps.snapTarget.x) {
          state.ticks.push(x);
        }
      }
    }

    this.setState(state);
  }

  componentWillUnmount() {
    this._interactable.unset();
  }

  get width() {
    return this._track.clientWidth;
  }
<commit_msg>add `handlePropUpdates` method to make the prop handling require less maintenance<commit_after>import React, { PropTypes } from 'react';
import classNames from 'classnames';
import interact from 'interact.js';
import isEmpty from 'lodash/isEmpty';
import { CommonPropTypes, PureComponent } from '../../../utils';

import Ticks from './ticks';
import { getSnapTargetFunc } from './util';
import style from './style.css';

export default class Track extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {};
    this.trackRef = this.trackRef.bind(this);
  }

  componentWillReceiveProps(nextProps) {
    this.setState(this.handlePropUpdates(this.props, nextProps));
  }

  handlePropUpdates(prevProps, nextProps) {
    const state = {};

    if (prevProps.snapTarget !== nextProps.snapTarget) {
      this.bindInteract(nextProps.snapTarget);

      if (nextProps.ticks) {
        state.ticks = [];
        for (let x = nextProps.snapTarget.x; x < this.width; x += nextProps.snapTarget.x) {
          state.ticks.push(x);
        }
      }
    }

    return state;
  }

  componentWillUnmount() {
    this._interactable.unset();
  }

  get width() {
    return this._track.clientWidth;
  }

{'fraction_non_alphanumeric': 0.1351111111111111, 'fraction_numerical': 0.0, 'mean_word_length': 3.1685185185185185, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6483189', 'n_tokens_mistral': 704, 'n_tokens_neox': 688, 'n_words': 157}