Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated PropTypes #3218

Merged
merged 3 commits into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You need to add `router` to your component's `contextTypes` to make the router o

```js
contextTypes: {
router: React.PropTypes.object.isRequired
router: Router.PropTypes.router
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/ConfirmingNavigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You can prevent a transition from happening or prompt the user before leaving a
const Home = React.createClass({

contextTypes: {
router: React.PropTypes.object
router: Router.PropTypes.router
},

componentDidMount() {
Expand Down
23 changes: 16 additions & 7 deletions modules/PropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export function falsy(props, propName, componentName) {

export const history = shape({
listen: func.isRequired,
pushState: func.isRequired,
replaceState: func.isRequired,
go: func.isRequired
push: func.isRequired,
replace: func.isRequired,
go: func.isRequired,
goBack: func.isRequired,
goForward: func.isRequired
})

export const location = shape({
Expand All @@ -27,11 +29,18 @@ export const components = oneOfType([ component, object ])
export const route = oneOfType([ object, element ])
export const routes = oneOfType([ route, arrayOf(route) ])

export const router = shape({
push: func.isRequired,
replace: func.isRequired,
go: func.isRequired,
goBack: func.isRequired,
goForward: func.isRequired,
setRouteLeaveHook: func.isRequired,
isActive: func.isRequired
})

export default {
falsy,
history,
location,
component,
components,
route
router
}
3 changes: 2 additions & 1 deletion modules/__tests__/RouterContext-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'
import { render, unmountComponentAtNode } from 'react-dom'

import match from '../match'
import { router as routerPropType } from '../PropTypes'
import RouterContext from '../RouterContext'
import { createRouterObject } from '../RouterUtils'

Expand Down Expand Up @@ -41,7 +42,7 @@ describe('RouterContext', () => {
}

Component.contextTypes = {
router: React.PropTypes.object.isRequired
router: routerPropType.isRequired
}

routes = { path: '/', component: Component }
Expand Down
5 changes: 3 additions & 2 deletions modules/__tests__/transitionHooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import expect, { spyOn } from 'expect'
import React, { Component } from 'react'
import { render, unmountComponentAtNode } from 'react-dom'
import createHistory from '../createMemoryHistory'
import { router as routerPropType } from '../PropTypes'
import execSteps from './execSteps'
import Router from '../Router'

Expand Down Expand Up @@ -42,7 +43,7 @@ describe('When a router enters a branch', function () {
}

NewsFeed.contextTypes = {
router: React.PropTypes.object.isRequired
router: routerPropType.isRequired
}

class Inbox extends Component {
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('When a router enters a branch', function () {
}

User.contextTypes = {
router: React.PropTypes.object.isRequired
router: routerPropType.isRequired
}

NewsFeedRoute = {
Expand Down
10 changes: 5 additions & 5 deletions upgrade-guides/v2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Access `location` from `this.props.location` of your `Route` component. If you'd
// v2.0.x
const RouteComponent = React.createClass({
childContextTypes: {
location: React.PropTypes.object
location: Router.PropTypes.location
},

getChildContext() {
Expand All @@ -136,7 +136,7 @@ const RouteComponent = React.createClass({
// 2.0.0
const RouteComponent = React.createClass({
contextTypes: {
route: React.PropTypes.object
route: Router.PropTypes.route
},
getChildContext() {
return {
Expand All @@ -160,7 +160,7 @@ const RouteComponent = React.createClass({
// v2.0.0
const RouteComponent = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
router: Router.PropTypes.router.isRequired
},
componentDidMount() {
const { route } = this.props
Expand Down Expand Up @@ -204,7 +204,7 @@ const RouteComponent = React.createClass({
// v2.0.0
const RouteComponent = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
router: Router.PropTypes.router.isRequired
},
someHandler() {
this.context.router.push(...)
Expand All @@ -229,7 +229,7 @@ const DeepComponent = React.createClass({
// 1) Use context.router (especially if on the server)
const DeepComponent = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
router: Router.PropTypes.router.isRequired
},
handleSubmit() {
this.context.router.push(...)
Expand Down