<commit_before>var React = require('react');
var utils= require('../utilities/helpers');
var ProgressBall = require('./ProgressBall');
var ProgressBar = require('./ProgressBar');
var classNames = require('classnames');

var ProgressTrack = React.createClass({
  
  getInitialState: function(){
    return {mouseDown: false}
  },

  handleRelease: function(e){
    this.handleClick(e);
    this.setState({mouseDown: false});
  },

  handleMove: function(e){
    if (this.state.mouseDown){
      this.handleClick(e);
    }
  },

  handleClick: function(e){

    this.setState({mouseDown: true});

    var barX, barWidth, x, newPosition, target;

    target = React.findDOMNode(this);

    barX = utils.position.getOffX(target);
    barWidth = target.offsetWidth;
    x = (e.clientX - barX);
    newPosition = (x / barWidth);

    if (this.props.sound && this.props.sound.duration) {

      this.props.sound.setPosition(this.props.sound.duration * newPosition);
      // a little hackish: ensure UI updates immediately with current position, even if audio is buffering and hasn't moved there yet.
      this.props.sound._iO.whileplaying.apply(this.props.sound);

    }
    
  },

  render: function(){

    var classes = classNames('sm2-progress-track',
    {'dragging': this.state.mouseDown});
    
    return (
      
      /*jshint ignore:start */
      <div className={classes} onMouseDown={this.handleClick} onMouseMove={this.handleMove} onMouseUp={this.handleRelease}>
        <ProgressBar  position={this.props.position} duration={this.props.duration} />
        <ProgressBall ref='progressBall' position={this.props.position} duration={this.props.duration} />
      </div>
      /*jshint ignore:end */
    );
  }
});

module.exports = ProgressTrack;<commit_msg>simplify the event handling find the DOM node early and assign to target to do it once.<commit_after>var React = require('react');
var utils= require('../utilities/helpers');
var ProgressBall = require('./ProgressBall');
var ProgressBar = require('./ProgressBar');
var classNames = require('classnames');

var ProgressTrack = React.createClass({
  
  componentDidMount: function() {
    this.target = React.findDOMNode(this);
  },

  componentWillUnmount: function() {
  },

  handleRelease: function(e){

    window.removeEventListener('mousemove', this.handleMouse);

    if (e.preventDefault) {
      e.preventDefault();
    }

    window.removeEventListener('mouseup', this.handleRelease);

  },

  handleMouse: function(e){

    var barX, barWidth, x, newPosition;

    this.target = React.findDOMNode(this);

    barX = utils.position.getOffX(this.target);
    barWidth = this.target.offsetWidth;
    x = (e.clientX - barX);
    newPosition = (x / barWidth);

    if (this.props.sound && this.props.sound.duration) {
      this.props.sound.setPosition(this.props.sound.duration * newPosition);
      // a little hackish: ensure UI updates immediately with current position, even if audio is buffering and hasn't moved there yet.
      this.props.sound._iO.whileplaying.apply(this.props.sound);
    }
    
    if (e.preventDefault) {
      e.preventDefault();
    }
    
  },

  handleClick: function(e){

    window.addEventListener('mousemove', this.handleMouse);
    window.addEventListener('mouseup', this.handleRelease);

    return this.handleMouse(e);

  },

  render: function(){

    var classes = classNames('sm2-progress-track');
    
    return (
      
      /*jshint ignore:start */
      <div ref='progressTrack' className={classes} onMouseDown={this.handleClick} >
        <ProgressBar  position={this.props.position} duration={this.props.duration} />
        <ProgressBall ref='progressBall' position={this.props.position} duration={this.props.duration} />
      </div>
      /*jshint ignore:end */
    );
  }
});

module.exports = ProgressTrack;
{'fraction_non_alphanumeric': 0.14006259780907668, 'fraction_numerical': 0.0005216484089723526, 'mean_word_length': 3.443800695249131, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3850746', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1124, 'n_words': 236}