<commit_before>var React = require('react');
var merge = require('react/lib/merge');
var invariant = require('react/lib/invariant');
var Route = require('./Route');
var History = require('./history/History');
var Request = require('./Request');
var Response = require('./Response');
var RoutingContext = require('./RoutingContext');
var Unhandled = require('./errors/Unhandled');
var once = require('once');
var parseDispatchArgs = require('./parseDispatchArgs');


var delayed = function(fn) {
  return function() {
    var args = arguments;
    var self = this;
    var fnWithArgs = function() {
      return fn.apply(self, args);
    };
    setTimeout(fnWithArgs, 0);
  };
};

var PropTypes = React.PropTypes;

/**
 * Creates a new router class. Router classes are React component classes which
 * manage the state of another component (a "view") by giving them props
 * decomposed from paths.
 */
function createRouterClass(opts) {
  var routes = Array.prototype.slice.call(arguments, 0);
  var rootURL = (opts && opts.rootURL || '/');

  var Router = React.createClass({
    propTypes: {
      path: PropTypes.string,
      history: PropTypes.object,
      initialViewProps: PropTypes.object
    },
    getDefaultProps: function() {
      return {
        initialViewProps: {},
        history: new History()
      };
    },
    getInitialState: function() {
      return {
        viewProps: this.props.initialViewProps || {}
      };
    },

    /**
     * Has the router been provided with a path or does it manage its own state?
     */
    isControlled: function() {
      return this.props.path != null;
    },

    componentDidMount: function() {
      if (this.isControlled())
        return;

      var history = this.props.history;

      // Start listening for history changes.
      history.start();

      // Dispatch for the initial route.
      this.dispatch(history.current());
    },
    componentWillMount: function() {
      if (this.isControlled()) {
        this.dispatch(this.props.path);
      }
    },
    render: function() {
      return this.state.view(this.state.viewProps);
    },

    dispatch: function(url, callback) {
      // TODO: Cancel the currently pending request, if any.
      //
      // // React currently (0.10) has a bug (#1740) that prevents us from storing
      // // the pending request in state. /:
      // this.pendingRequest = req;
      Router.dispatch(this, url, callback);<commit_msg>Throw any errors from dispatching<commit_after>var React = require('react');
var merge = require('react/lib/merge');
var invariant = require('react/lib/invariant');
var Route = require('./Route');
var History = require('./history/History');
var Request = require('./Request');
var Response = require('./Response');
var RoutingContext = require('./RoutingContext');
var Unhandled = require('./errors/Unhandled');
var once = require('once');
var parseDispatchArgs = require('./parseDispatchArgs');


var delayed = function(fn) {
  return function() {
    var args = arguments;
    var self = this;
    var fnWithArgs = function() {
      return fn.apply(self, args);
    };
    setTimeout(fnWithArgs, 0);
  };
};

var PropTypes = React.PropTypes;

/**
 * Creates a new router class. Router classes are React component classes which
 * manage the state of another component (a "view") by giving them props
 * decomposed from paths.
 */
function createRouterClass(opts) {
  var routes = Array.prototype.slice.call(arguments, 0);
  var rootURL = (opts && opts.rootURL || '/');

  var Router = React.createClass({
    propTypes: {
      path: PropTypes.string,
      history: PropTypes.object,
      initialViewProps: PropTypes.object
    },
    getDefaultProps: function() {
      return {
        initialViewProps: {},
        history: new History()
      };
    },
    getInitialState: function() {
      return {
        viewProps: this.props.initialViewProps || {}
      };
    },

    /**
     * Has the router been provided with a path or does it manage its own state?
     */
    isControlled: function() {
      return this.props.path != null;
    },

    componentDidMount: function() {
      if (this.isControlled())
        return;

      var history = this.props.history;

      // Start listening for history changes.
      history.start();

      // Dispatch for the initial route.
      this.dispatch(history.current());
    },
    componentWillMount: function() {
      if (this.isControlled()) {
        this.dispatch(this.props.path);
      }
    },
    render: function() {
      return this.state.view(this.state.viewProps);
    },

    dispatch: function(url) {
      // TODO: Cancel the currently pending request, if any.
      //
      // // React currently (0.10) has a bug (#1740) that prevents us from storing
      // // the pending request in state. /:
      // this.pendingRequest = req;
      Router.dispatch(this, url, function(err) {
        throw err;
      });
{'fraction_non_alphanumeric': 0.1345764085934333, 'fraction_numerical': 0.0036481556546412645, 'mean_word_length': 2.7161144578313254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2453218', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1354, 'n_words': 396}