<commit_before>import React, { PropTypes } from 'react'
import matchRoutes from './matchRoutes'
import withHistory from './withHistory'
import {
  action as actionType,
  location as locationType
} from './PropTypes'

/**
 * The public API for matching a single pattern.
 */
class Route extends React.Component {
  static propTypes = {
    action: actionType.isRequired,
    location: locationType.isRequired,
    pattern: PropTypes.string,
    exact: PropTypes.bool,
    component: PropTypes.func,
    render: PropTypes.func
  }

  static defaultProps = {
    exact: false
  }

  handleRouteChange(nextState, callback) {
    const child = this.child

    if (typeof child.routeWillChange === 'function') {
      const { action, location, pattern, exact, component, render, ...props } = this.props // eslint-disable-line no-unused-vars
      const { match } = matchRoutes([ { pattern, exact } ], nextState.location.pathname)

      // Compute the next props the component will
      // receive so it has access to params, etc.
      const nextChildProps = {
        ...props,
        ...match,
        action: nextState.action,
        location: nextState.location,
        matched: match != null
      }

      child.routeWillChange.call(child, nextChildProps, callback)
    } else {
      callback()
    }
  }

  updateChild = (child) => {
    this.child = child
  }

  render() {
    const { action, location, pattern, exact, component, render, ...props } = this.props
    const { match } = matchRoutes([ { pattern, exact } ], location.pathname)
    const matched = match != null

    const childProps = {
      ...props,
      ...match,
      action,
      location,
      matched,
      ref: this.updateChild
    }

    return (
      render ? (
        render(childProps)
      ) : (
        matched ? React.createElement(component, childProps) : null
      )
    )
  }<commit_msg>Give proper ref to child generated by <Route render><commit_after>import React, { PropTypes } from 'react'
import matchRoutes from './matchRoutes'
import withHistory from './withHistory'
import {
  action as actionType,
  location as locationType
} from './PropTypes'

/**
 * The public API for matching a single pattern.
 */
class Route extends React.Component {
  static propTypes = {
    action: actionType.isRequired,
    location: locationType.isRequired,
    pattern: PropTypes.string,
    exact: PropTypes.bool,
    component: PropTypes.func,
    render: PropTypes.func
  }

  static defaultProps = {
    exact: false
  }

  handleRouteChange(nextState, callback) {
    const child = this.child

    if (typeof child.routeWillChange === 'function') {
      const { action, location, pattern, exact, component, render, ...props } = this.props // eslint-disable-line no-unused-vars
      const { match } = matchRoutes([ { pattern, exact } ], nextState.location.pathname)

      // Compute the next props the component will
      // receive so it has access to params, etc.
      const nextChildProps = {
        ...props,
        ...match,
        action: nextState.action,
        location: nextState.location,
        matched: match != null
      }

      child.routeWillChange.call(child, nextChildProps, callback)
    } else {
      callback()
    }
  }

  updateChild = (child) => {
    this.child = child
  }

  render() {
    const { action, location, pattern, exact, component, render, ...props } = this.props
    const { match } = matchRoutes([ { pattern, exact } ], location.pathname)
    const matched = match != null

    const childProps = {
      ...props,
      ...match,
      action,
      location,
      matched,
      ref: this.updateChild
    }

    return (
      render ? (
        React.cloneElement(render(childProps), { ref: this.updateChild })
      ) : (
        matched ? React.createElement(component, childProps) : null
      )
    )
  }
{'fraction_non_alphanumeric': 0.11347150259067358, 'fraction_numerical': 0.0, 'mean_word_length': 2.4878048780487805, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '7102122', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1076, 'n_words': 308}