Skip to content

Commit

Permalink
Merge pull request #3340 from reactjs/remove-context-history-location
Browse files Browse the repository at this point in the history
[3.0] Remove deprecations.
  • Loading branch information
taion committed Apr 21, 2016
2 parents b3c37a8 + 1a5666e commit da81910
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 1,575 deletions.
20 changes: 0 additions & 20 deletions modules/History.js

This file was deleted.

65 changes: 0 additions & 65 deletions modules/Lifecycle.js

This file was deleted.

26 changes: 5 additions & 21 deletions modules/Link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import warning from './routerWarning'
import { routerShape } from './PropTypes'

const { bool, object, string, func, oneOfType } = React.PropTypes
Expand All @@ -21,14 +20,6 @@ function isEmptyObject(object) {
return true
}

function createLocationDescriptor(to, { query, hash, state }) {
if (query || hash || state) {
return { pathname: to, query, hash, state }
}

return to
}

/**
* A <Link> is used to create an <a> element that links to a route.
* When that route is active, the link gets the value of its
Expand Down Expand Up @@ -95,29 +86,22 @@ const Link = React.createClass({
event.preventDefault()

if (allowTransition) {
const { to, query, hash, state } = this.props
const location = createLocationDescriptor(to, { query, hash, state })
const { to } = this.props

this.context.router.push(location)
this.context.router.push(to)
}
},

render() {
const { to, query, hash, state, activeClassName, activeStyle, onlyActiveOnIndex, ...props } = this.props
warning(
!(query || hash || state),
'the `query`, `hash`, and `state` props on `<Link>` are deprecated, use `<Link to={{ pathname, query, hash, state }}/>. http://tiny.cc/router-isActivedeprecated'
)

const { to, activeClassName, activeStyle, onlyActiveOnIndex, ...props } = this.props
// Ignore if rendered outside the context of router, simplifies unit testing.
const { router } = this.context

if (router) {
const location = createLocationDescriptor(to, { query, hash, state })
props.href = router.createHref(location)
props.href = router.createHref(to)

if (activeClassName || (activeStyle != null && !isEmptyObject(activeStyle))) {
if (router.isActive(location, onlyActiveOnIndex)) {
if (router.isActive(to, onlyActiveOnIndex)) {
if (activeClassName) {
if (props.className) {
props.className += ` ${activeClassName}`
Expand Down
34 changes: 0 additions & 34 deletions modules/RouteContext.js

This file was deleted.

45 changes: 5 additions & 40 deletions modules/Router.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import createHashHistory from 'history/lib/createHashHistory'
import useQueries from 'history/lib/useQueries'
import React from 'react'

import createTransitionManager from './createTransitionManager'
import { routes } from './InternalPropTypes'
import RouterContext from './RouterContext'
import { createRoutes } from './RouteUtils'
import { createRouterObject, createRoutingHistory } from './RouterUtils'
import { createRouterObject } from './RouterUtils'
import warning from './routerWarning'

function isDeprecatedHistory(history) {
return !history || !history.__v2_compatible__
}

const { func, object } = React.PropTypes

/**
Expand Down Expand Up @@ -62,13 +56,7 @@ const Router = React.createClass({
},

componentWillMount() {
const { parseQueryString, stringifyQuery } = this.props
warning(
!(parseQueryString || stringifyQuery),
'`parseQueryString` and `stringifyQuery` are deprecated. Please create a custom history. http://tiny.cc/router-customquerystring'
)

const { history, transitionManager, router } = this.createRouterObjects()
const { transitionManager, router } = this.createRouterObjects()

this._unlisten = transitionManager.listen((error, state) => {
if (error) {
Expand All @@ -78,7 +66,6 @@ const Router = React.createClass({
}
})

this.history = history
this.router = router
},

Expand All @@ -91,34 +78,13 @@ const Router = React.createClass({
let { history } = this.props
const { routes, children } = this.props

if (isDeprecatedHistory(history)) {
history = this.wrapDeprecatedHistory(history)
}

const transitionManager = createTransitionManager(
history, createRoutes(routes || children)
history,
createRoutes(routes || children)
)
const router = createRouterObject(history, transitionManager)
const routingHistory = createRoutingHistory(history, transitionManager)

return { history: routingHistory, transitionManager, router }
},

wrapDeprecatedHistory(history) {
const { parseQueryString, stringifyQuery } = this.props

let createHistory
if (history) {
warning(false, 'It appears you have provided a deprecated history object to `<Router/>`, please use a history provided by ' +
'React Router with `import { browserHistory } from \'react-router\'` or `import { hashHistory } from \'react-router\'`. ' +
'If you are using a custom history please create it with `useRouterHistory`, see http://tiny.cc/router-usinghistory for details.')
createHistory = () => history
} else {
warning(false, '`Router` no longer defaults the history prop to hash history. Please use the `hashHistory` singleton instead. http://tiny.cc/router-defaulthistory')
createHistory = createHashHistory
}

return useQueries(createHistory)({ parseQueryString, stringifyQuery })
return { transitionManager, router }
},

/* istanbul ignore next: sanity check */
Expand Down Expand Up @@ -153,7 +119,6 @@ const Router = React.createClass({

return render({
...props,
history: this.history,
router: this.router,
location,
routes,
Expand Down
26 changes: 3 additions & 23 deletions modules/RouterContext.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import invariant from 'invariant'
import React from 'react'

import deprecateObjectProperties from './deprecateObjectProperties'
import getRouteParams from './getRouteParams'
import { isReactChildren } from './RouteUtils'
import warning from './routerWarning'

const { array, func, object } = React.PropTypes

Expand All @@ -15,9 +13,7 @@ const { array, func, object } = React.PropTypes
const RouterContext = React.createClass({

propTypes: {
history: object,
router: object.isRequired,
location: object.isRequired,
routes: array.isRequired,
params: object.isRequired,
components: array.isRequired,
Expand All @@ -31,36 +27,21 @@ const RouterContext = React.createClass({
},

childContextTypes: {
history: object,
location: object.isRequired,
router: object.isRequired
},

getChildContext() {
let { router, history, location } = this.props
if (!router) {
warning(false, '`<RouterContext>` expects a `router` rather than a `history`')

router = {
...history,
setRouteLeaveHook: history.listenBeforeLeavingRoute
}
delete router.listenBeforeLeavingRoute
}

if (__DEV__) {
location = deprecateObjectProperties(location, '`context.location` is deprecated, please use a route component\'s `props.location` instead. http://tiny.cc/router-accessinglocation')
return {
router: this.props.router
}

return { history, location, router }
},

createElement(component, props) {
return component == null ? null : this.props.createElement(component, props)
},

render() {
const { history, location, routes, params, components } = this.props
const { location, routes, params, components } = this.props
let element = null

if (components) {
Expand All @@ -71,7 +52,6 @@ const RouterContext = React.createClass({
const route = routes[index]
const routeParams = getRouteParams(route, params)
const props = {
history,
location,
params,
route,
Expand Down
19 changes: 0 additions & 19 deletions modules/RouterUtils.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import deprecateObjectProperties from './deprecateObjectProperties'

export function createRouterObject(history, transitionManager) {
return {
...history,
setRouteLeaveHook: transitionManager.listenBeforeLeavingRoute,
isActive: transitionManager.isActive
}
}

// deprecated
export function createRoutingHistory(history, transitionManager) {
history = {
...history,
...transitionManager
}

if (__DEV__) {
history = deprecateObjectProperties(
history,
'`props.history` and `context.history` are deprecated. Please use `context.router`. http://tiny.cc/router-contextchanges'
)
}

return history
}
17 changes: 1 addition & 16 deletions modules/TransitionUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { loopAsync } from './AsyncUtils'
import warning from './routerWarning'

function createTransitionHook(hook, route, asyncArity) {
return function (...args) {
Expand Down Expand Up @@ -38,21 +37,7 @@ function runTransitionHooks(length, iter, callback) {
}

let redirectInfo
function replace(location, deprecatedPathname, deprecatedQuery) {
if (deprecatedPathname) {
warning(
false,
'`replaceState(state, pathname, query) is deprecated; use `replace(location)` with a location descriptor instead. http://tiny.cc/router-isActivedeprecated'
)
redirectInfo = {
pathname: deprecatedPathname,
query: deprecatedQuery,
state: location
}

return
}

function replace(location) {
redirectInfo = location
}

Expand Down
Loading

0 comments on commit da81910

Please sign in to comment.