<commit_before>var React = require('react');

/************* Helper Functions **************/
function isElementType(element, expectedType) {
  return getElementType(element) == expectedType;
}

function getElementType(element) {
  return element.type.displayName || element.type;
}

var PillSelector = React.createClass({
  statics: {
    ONE_OR_NONE: 0,
    ALWAYS_ONE: 1
  },
  componentWillMount: function() {
    var errors = "";
    var children = this.props.children;
    
    children.forEach(function(child) {
      if(!isElementType(child, "li")) {
        errors += "\r\nFound " + getElementType(child) + " element in PillSelector. All elements should be 'li'";
      }
    });

    if(errors !== "") {
      throw new Error(errors);
    }
  },
  propTypes: {
    children: React.PropTypes.arrayOf(React.PropTypes.element),
    selectionMode: React.PropTypes.number,
    selectedIndex: React.PropTypes.number,
    onItemClicked: React.PropTypes.func,
    callClickOnLoad: React.PropTypes.bool
  },
  componentDidMount: function() {
    if(!this.props.callClickOnLoad || this.state.selected === null) {
      return;
    }

    var id = this.state.selected;
    var child = this.props.children[id];

    this.props.onItemClicked(id, child.props.data);
  },
  getDefaultProps: function() {
    return {
      selectionMode: 1,
      selectedIndex: 0,
      onItemClicked: function () {},
      callClickOnLoad: true
    };
  },
  getInitialState: function() {
    return { selected: this.props.selectedIndex};
  },
  changeSelected: function(id) {
    if(this.props.selectionMode === PillSelector.ALWAYS_ONE) {
      this.setState({ selected: id });
      return;
    }

    var selected = this.state.selected === id ? null : id;
    this.setState({ selected: selected });
  },
  itemClickHandler: function(id, data, event) {
    this.changeSelected(id);
    this.props.onItemClicked(id, data);

    event.stopPropagation();
    event.preventDefault();
    return false;
  },
  render: function() {
    var children = this.props.children;

    var listItems = children.map(function (child, id) {
      var data = child.props.data;
      var isSelected = id === this.state.selected;
      var className = isSelected ? "ps-list-item ps-selected" : "ps-list-item";

      return (
        <li
          role="button"
          aria-pressed={isSelected}
          className={className}
          onMouseDown={this.itemClickHandler.bind(this, id, data)}>
          {child.props.children}
        </li>
      );
    }, this);

    return (
      <ul className="ps-list">
        {listItems}
      </ul>
    )
  }
});

module.exports = PillSelector;<commit_msg>Added keys to list items<commit_after>var React = require('react');

/************* Helper Functions **************/
function isElementType(element, expectedType) {
  return getElementType(element) == expectedType;
}

function getElementType(element) {
  return element.type.displayName || element.type;
}

var PillSelector = React.createClass({
  statics: {
    ONE_OR_NONE: 0,
    ALWAYS_ONE: 1
  },
  componentWillMount: function() {
    var errors = "";
    var children = this.props.children;
    
    children.forEach(function(child) {
      if(!isElementType(child, "li")) {
        errors += "\r\nFound " + getElementType(child) + " element in PillSelector. All elements should be 'li'";
      }
    });

    if(errors !== "") {
      throw new Error(errors);
    }
  },
  propTypes: {
    children: React.PropTypes.arrayOf(React.PropTypes.element),
    selectionMode: React.PropTypes.number,
    selectedIndex: React.PropTypes.number,
    onItemClicked: React.PropTypes.func,
    callClickOnLoad: React.PropTypes.bool
  },
  componentDidMount: function() {
    if(!this.props.callClickOnLoad || this.state.selected === null) {
      return;
    }

    var id = this.state.selected;
    var child = this.props.children[id];

    this.props.onItemClicked(id, child.props.data);
  },
  getDefaultProps: function() {
    return {
      selectionMode: 1,
      selectedIndex: 0,
      onItemClicked: function () {},
      callClickOnLoad: true
    };
  },
  getInitialState: function() {
    return { selected: this.props.selectedIndex};
  },
  changeSelected: function(id) {
    if(this.props.selectionMode === PillSelector.ALWAYS_ONE) {
      this.setState({ selected: id });
      return;
    }

    var selected = this.state.selected === id ? null : id;
    this.setState({ selected: selected });
  },
  itemClickHandler: function(id, data, event) {
    this.changeSelected(id);
    this.props.onItemClicked(id, data);

    event.stopPropagation();
    event.preventDefault();
    return false;
  },
  render: function() {
    var children = this.props.children;

    var listItems = children.map(function (child, id) {
      var data = child.props.data;
      var isSelected = id === this.state.selected;
      var className = isSelected ? "ps-list-item ps-selected" : "ps-list-item";

      return (
        <li
          key={id}
          role="button"
          aria-pressed={isSelected}
          className={className}
          onMouseDown={this.itemClickHandler.bind(this, id, data)}>
          {child.props.children}
        </li>
      );
    }, this);

    return (
      <ul className="ps-list">
        {listItems}
      </ul>
    )
  }
});

module.exports = PillSelector;
{'fraction_non_alphanumeric': 0.14544436146377893, 'fraction_numerical': 0.0014936519790888724, 'mean_word_length': 2.8373925501432664, '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': '1021937', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1635, 'n_words': 322}