<commit_before>/**
 * @jsx React.DOM
 */

var Slider = React.createClass({
  propTypes: {
    outerWidth: React.PropTypes.number,
    width: React.PropTypes.number.isRequired,
    leftwidth: React.PropTypes.number.isRequired,
    rightwidth: React.PropTypes.number.isRequired,
    leftNumber: React.PropTypes.number.isRequired,
    rightNumber: React.PropTypes.number,
    initialLeftNumber: React.PropTypes.number,
    initialRightNumber: React.PropTypes.number,
    scalingFunction: React.PropTypes.func,
    inverseScalingFunction: React.PropTypes.func,
    onSliderUpdate: React.PropTypes.func,
    onlyUpdateOnRelease: React.PropTypes.bool,
    unit: React.PropTypes.string,
    subset: React.PropTypes.bool
  },
  getDefaultProps: function() {
    return {
      unit: '',
      leftwidth: 0,
      rightwidth: 0,
      subset: false,
      scalingFunction: function(x, constantBase) {
        return Math.pow(x, 2) / Math.pow(constantBase, 2);
      },
      inverseScalingFunction: function(x, constantBase) {
        return Math.sqrt(x) / Math.sqrt(constantBase);
      },
      onSliderUpdate: function() {}
    }
  },
  getInitialState: function() {
    // invariant: left <= right
    return {
      left: 0,
      right: 0,
      leftNumber: this.props.leftNumber,
      rightNumber: this.props.rightNumber,
      storedState: undefined,
      storedNumber: this.props.leftNumber,
      leftActive: false,
      rightActive: false,
      isTouch: 'ontouchstart' in document,
      sliderStartX: undefined,
      sliderEndX: undefined
    }
  },
  componentWillReceiveProps: function(nextProps) {
    var that = this;
    if (this.state.rightNumber === undefined || this.state.leftNumber === undefined) {
      var stateObject = {
        leftNumber: nextProps.leftNumber,
        rightNumber: nextProps.rightNumber
      };
      this.setState(stateObject);
    }
  },
  getOtherDirection: function(thisDirection) {
    var directions = ["left", "right"];
    var otherIndex = (directions.indexOf(thisDirection) + 1) % 2;
    return directions[otherIndex];
  },

  sliderUpdater: function() {
    if (this.props.onlyUpdateOnRelease && (this.state.leftActive || this.state.rightActive)) {
      this.props.onSliderUpdate({
        leftNumber: this.state.leftNumber,
        rightNumber: this.state.rightNumber
      }, true);
    }
    this.setState({
      leftActive: false,
      rightActive: false
    });
    document.removeEventListener("mousemove", this.mouseDownHelper);
    document.removeEventListener("touchmove", this.mouseDownHelper);
  },

  componentDidMount: function() {
    document.addEventListener("mouseup", this.sliderUpdater);
    document.addEventListener("touchend", this.sliderUpdater);
    var stateObject = {};
    stateObject.leftNumber = parseInt(this.props.initialLeftNumber || this.props.leftNumber, 10);
    var setRightNumber;
    if (this.props.initialRightNumber) {
      setRightNumber = Math.min(this.props.initialRightNumber, this.props.rightNumber);
    } else {
      setRightNumber = this.props.rightNumber;
    }
    stateObject.rightNumber = parseInt(setRightNumber, 10);
    var addedState = this.addPositionsFromNumbers(stateObject, this.props.rightNumber);
    this.setState(addedState);
  },
  // a function of props and state
  moveConditionsMet: function(state) {
    var leftWithinBounds  = state.left >= 0 && state.left < this.props.width;
    var rightWithinBounds = state.right >= 0 && state.right < this.props.width;
    var leftNotCrossing   = (state.left + this.props.leftwidth) <= (this.props.width - state.right);
    var rightNotCrossing  = (this.props.width - state.right - this.props.rightwidth) >= state.left;
    return leftWithinBounds && rightWithinBounds && leftNotCrossing && rightNotCrossing;
  },
  // Typed conditions cannot go out of bounds, but they can cross
  typedConditionsMet: function(state) {
    return state.leftNumber <= state.rightNumber;
  },
  handleBlur: function(e) {
    var stateObject = {};
    var targetClassName = e.target.className;
    if (e.target.value.substr(1) === "")<commit_msg>Clean up document event listeners when component is unmounted.<commit_after>/**
 * @jsx React.DOM
 */

var Slider = React.createClass({
  propTypes: {
    outerWidth: React.PropTypes.number,
    width: React.PropTypes.number.isRequired,
    leftwidth: React.PropTypes.number.isRequired,
    rightwidth: React.PropTypes.number.isRequired,
    leftNumber: React.PropTypes.number.isRequired,
    rightNumber: React.PropTypes.number,
    initialLeftNumber: React.PropTypes.number,
    initialRightNumber: React.PropTypes.number,
    scalingFunction: React.PropTypes.func,
    inverseScalingFunction: React.PropTypes.func,
    onSliderUpdate: React.PropTypes.func,
    onlyUpdateOnRelease: React.PropTypes.bool,
    unit: React.PropTypes.string,
    subset: React.PropTypes.bool
  },
  getDefaultProps: function() {
    return {
      unit: '',
      leftwidth: 0,
      rightwidth: 0,
      subset: false,
      scalingFunction: function(x, constantBase) {
        return Math.pow(x, 2) / Math.pow(constantBase, 2);
      },
      inverseScalingFunction: function(x, constantBase) {
        return Math.sqrt(x) / Math.sqrt(constantBase);
      },
      onSliderUpdate: function() {}
    }
  },
  getInitialState: function() {
    // invariant: left <= right
    return {
      left: 0,
      right: 0,
      leftNumber: this.props.leftNumber,
      rightNumber: this.props.rightNumber,
      storedState: undefined,
      storedNumber: this.props.leftNumber,
      leftActive: false,
      rightActive: false,
      isTouch: 'ontouchstart' in document,
      sliderStartX: undefined,
      sliderEndX: undefined
    }
  },
  componentWillReceiveProps: function(nextProps) {
    var that = this;
    if (this.state.rightNumber === undefined || this.state.leftNumber === undefined) {
      var stateObject = {
        leftNumber: nextProps.leftNumber,
        rightNumber: nextProps.rightNumber
      };
      this.setState(stateObject);
    }
  },
  getOtherDirection: function(thisDirection) {
    var directions = ["left", "right"];
    var otherIndex = (directions.indexOf(thisDirection) + 1) % 2;
    return directions[otherIndex];
  },

  sliderUpdater: function() {
    if (this.props.onlyUpdateOnRelease && (this.state.leftActive || this.state.rightActive)) {
      this.props.onSliderUpdate({
        leftNumber: this.state.leftNumber,
        rightNumber: this.state.rightNumber
      }, true);
    }
    this.setState({
      leftActive: false,
      rightActive: false
    });
    document.removeEventListener("mousemove", this.mouseDownHelper);
    document.removeEventListener("touchmove", this.mouseDownHelper);
  },

  componentDidMount: function() {
    document.addEventListener("mouseup", this.sliderUpdater);
    document.addEventListener("touchend", this.sliderUpdater);
    var stateObject = {};
    stateObject.leftNumber = parseInt(this.props.initialLeftNumber || this.props.leftNumber, 10);
    var setRightNumber;
    if (this.props.initialRightNumber) {
      setRightNumber = Math.min(this.props.initialRightNumber, this.props.rightNumber);
    } else {
      setRightNumber = this.props.rightNumber;
    }
    stateObject.rightNumber = parseInt(setRightNumber, 10);
    var addedState = this.addPositionsFromNumbers(stateObject, this.props.rightNumber);
    this.setState(addedState);
  },
  componentWillUnmount: function() {
    document.removeEventListener("mouseup", this.sliderUpdater);
    document.removeEventListener("touchend", this.sliderUpdater);
  },
  // a function of props and state
  moveConditionsMet: function(state) {
    var leftWithinBounds  = state.left >= 0 && state.left < this.props.width;
    var rightWithinBounds = state.right >= 0 && state.right < this.props.width;
    var leftNotCrossing   = (state.left + this.props.leftwidth) <= (this.props.width - state.right);
    var rightNotCrossing  = (this.props.width - state.right - this.props.rightwidth) >= state.left;
    return leftWithinBounds && rightWithinBounds && leftNotCrossing && rightNotCrossing;
  },
  // Typed conditions cannot go out of bounds, but they can cross
  typedConditionsMet: function(state) {
    return state.leftNumber <= state.rightNumber;
  },
  handleBlur: function(e) {
    var stateObject = {};
    var targetClassName = e.target.className;
    if (e.target.value.substr(1) === "")
{'fraction_non_alphanumeric': 0.11812990720913633, 'fraction_numerical': 0.0035688793718772305, 'mean_word_length': 3.4108079748163695, 'pattern_counts': {'":': 0, '<': 13, '<?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': '295350', 'n_tokens_mistral': 2490, 'n_tokens_neox': 2468, 'n_words': 484}