<commit_before>var React = require('react');
var invariant = require('react/lib/invariant');
var path = require('../path');
var urlStore = require('../stores/url-store');

var RESERVED_PROPS = {
  activeClass: true,
  to: true,
  query: true,
  children: true // ReactChildren
};

var Link = React.createClass({

  statics: {

    /**
     * Returns an href that can be used to link to the given path or
     * route name, params, and query.
     */
    makeHref: function (to, params, query) {
      return makeHref(resolveTo(to), params, query);
    }

  },

  propTypes: {
    activeClass: React.PropTypes.string.isRequired,
    to: React.PropTypes.string,
    query: React.PropTypes.object
  },

  getDefaultProps: function () {
    return {
      activeClass: 'active'
    };
  },

  getInitialState: function () {
    return {
      isActive: false
    };
  },

  /**
   * Returns the path this <Link> uses to match the URL.
   */
  getPath: function () {
    if (this.props.to)
      return resolveTo(this.props.to);

    return '';
  },

  /**
   * Returns a hash of URL parameters this <Link> interpolates into its path (see getPath).
   */
  getParams: function () {
    var props = this.props;
    var params = {};

    for (var name in props) {
      if (!RESERVED_PROPS[name]) {
        params[name] = props[name];
      }
    }

    return params;
  },

  /**
   * Returns a hash of query string parameters this <Link> appends to its path (see getPath).
   */
  getQuery: function () {
    return this.props.query;
  },

  /**
   * Returns the value of the "href" attribute to use on the <a> element.
   */
  getHref: function () {
    return makeHref(this.getPath(), this.getParams(), this.getQuery());
  },

  /**
   * Returns the value of the "class" attribute to use on the <a> element, which contains
   * the value of the "activeClass" property when this <Link> is active.
   */
  getClassName: function () {
    var className = this.props.className || '';

    if (this.state.isActive)
      return className + ' ' + this.props.activeClass;

    return className;
  },

  componentWillMount: function () {
    urlStore.subscribe(this.handleRouteChange);
    this.updateActive(urlStore.getCurrentPath());
  },

  componentWillUnmount: function () {
    urlStore.unsubscribe(this.handleRouteChange);
  },

  handleRouteChange: function () {
    this.updateActive(urlStore.getCurrentPath());
  },
<commit_msg>Add activeClassName prop to <Link>s<commit_after>var React = require('react');
var invariant = require('react/lib/invariant');
var path = require('../path');
var urlStore = require('../stores/url-store');

var RESERVED_PROPS = {
  activeClassName: true,
  to: true,
  query: true,
  children: true // ReactChildren
};

var Link = React.createClass({

  statics: {

    /**
     * Returns an href that can be used to link to the given path or
     * route name, params, and query.
     */
    makeHref: function (to, params, query) {
      return makeHref(resolveTo(to), params, query);
    }

  },

  propTypes: {
    activeClassName: React.PropTypes.string.isRequired,
    to: React.PropTypes.string,
    query: React.PropTypes.object
  },

  getDefaultProps: function () {
    return {
      activeClassName: 'active'
    };
  },

  getInitialState: function () {
    return {
      isActive: false
    };
  },

  /**
   * Returns the path this <Link> uses to match the URL.
   */
  getPath: function () {
    if (this.props.to)
      return resolveTo(this.props.to);

    return '';
  },

  /**
   * Returns a hash of URL parameters this <Link> interpolates into its path (see getPath).
   */
  getParams: function () {
    var props = this.props;
    var params = {};

    for (var name in props) {
      if (!RESERVED_PROPS[name]) {
        params[name] = props[name];
      }
    }

    return params;
  },

  /**
   * Returns a hash of query string parameters this <Link> appends to its path (see getPath).
   */
  getQuery: function () {
    return this.props.query;
  },

  /**
   * Returns the value of the "href" attribute to use on the <a> element.
   */
  getHref: function () {
    return makeHref(this.getPath(), this.getParams(), this.getQuery());
  },

  /**
   * Returns the value of the "class" attribute to use on the <a> element, which contains
   * the value of the "activeClassName" property when this <Link> is active.
   */
  getClassName: function () {
    var className = this.props.className || '';

    if (this.state.isActive)
      return className + ' ' + this.props.activeClassName;

    return className;
  },

  componentWillMount: function () {
    urlStore.subscribe(this.handleRouteChange);
    this.updateActive(urlStore.getCurrentPath());
  },

  componentWillUnmount: function () {
    urlStore.unsubscribe(this.handleRouteChange);
  },

  handleRouteChange: function () {
    this.updateActive(urlStore.getCurrentPath());
  },

{'fraction_non_alphanumeric': 0.13316993464052287, 'fraction_numerical': 0.0, 'mean_word_length': 2.793183578621224, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4402765', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1492, 'n_words': 418}