<commit_before>/* eslint-env browser */

import React, { PropTypes, Component } from 'react';
import { connect } from 'react-redux';
import RouterContext from './RouterContext';
import { once } from './utils';
import { getRoutesByName } from './route';
import { changeStateAction } from './redux-reducer';
import { router as routerPropTypes } from './propTypes';





class Router extends Component {
  static propTypes = {
    children: PropTypes.node.isRequired,
    routerState: PropTypes.shape({
      name: PropTypes.string.isRequired,
      params: PropTypes.object.isRequired
    }).isRequired,
    history: PropTypes.shape({ // instance of history.js
      location: PropTypes.shape({
        pathname: PropTypes.string,
        search: PropTypes.string,
        hash: PropTypes.string
      }).isRequired,
      push: PropTypes.func.isRequired,
      listen: PropTypes.func.isRequired,
      replace: PropTypes.func.isRequired,
      createHref: PropTypes.func.isRequired
    }).isRequired,
    changeStateAction: PropTypes.func // from connect
  };

  static childContextTypes = {
    router: routerPropTypes
  };

  getChildContext () {
    return { router: this._router };
  }

  constructor (...args) {
    super(...args);

    this._router = new RouterContext();
  }

  componentWillMount () {
    const { changeStateAction, history, routerState } = this.props;

    this._router.setRoutes(getRoutesByName());
    this._router.setHistory(history);
    this._router.setState(routerState);

    changeStateAction(history.location, history.action);

    this._historyCleanupListener = once(history.listen((location, action) => {
      changeStateAction(location, action);
    }));
  }

  componentWillUpdate ({ routerState }) {
    this._router.setState(routerState);
  }

  componentWillUnmount () {
    this._historyCleanupListener();
    this._router.destroy();
    this._router = null;
  }

  render () {
    const { routerState, children } = this.props;

    return routerState.name ? children : <noscript />;
  }
}



export default connect(
  ({ routerState }) => ({
    routerState<commit_msg>fix router<commit_after>/* eslint-env browser */

import React, { PropTypes, Component } from 'react';
import { connect } from 'react-redux';
import RouterContext from './RouterContext';
import { once } from './utils';
import { getRoutesByName } from './route';
import { changeStateAction } from './redux-reducer';
import { router as routerPropTypes } from './propTypes';





class Router extends Component {
  static propTypes = {
    children: PropTypes.node.isRequired,
    routerState: PropTypes.shape({
      name: PropTypes.string.isRequired,
      params: PropTypes.object.isRequired
    }).isRequired,
    history: PropTypes.shape({ // instance of history.js
      location: PropTypes.shape({
        pathname: PropTypes.string,
        search: PropTypes.string,
        hash: PropTypes.string
      }).isRequired,
      push: PropTypes.func.isRequired,
      listen: PropTypes.func.isRequired,
      replace: PropTypes.func.isRequired,
      createHref: PropTypes.func.isRequired
    }).isRequired,
    changeStateAction: PropTypes.func // from connect
  };

  static childContextTypes = {
    router: routerPropTypes
  };

  getChildContext () {
    return { router: this._router };
  }

  constructor (...args) {
    super(...args);

    this._router = new RouterContext();
  }

  componentWillMount () {
    const { changeStateAction, history, routerState } = this.props;

    this._router.setRoutes(getRoutesByName());
    this._router.setHistory(history);
    this._router.setState(routerState);

    changeStateAction(history.location, history.action);

    this._historyCleanupListener = once(history.listen((location, action) => {
      changeStateAction(location, action);
    }));
  }

  componentWillUpdate ({ routerState }) {
    this._router.setState(routerState);
  }

  componentWillUnmount () {
    this._historyCleanupListener();
    this._router.destroy();
    this._router = null;
  }

  render () {
    const { children } = this.props;

    return this._router.getState().name ? children : <noscript />;
  }
}



export default connect(
  ({ routerState }) => ({
    routerState
{'fraction_non_alphanumeric': 0.12582938388625592, 'fraction_numerical': 0.0, 'mean_word_length': 3.2852791878172587, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1012036', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1198, 'n_words': 257}