Skip to content

Dependency inject React. #2031

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

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 12 additions & 7 deletions modules/History.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { history } from './PropTypes'
import createPropTypes from './PropTypes'

const History = {
export default function createHistory(React) {
const { history } = createPropTypes(React)

contextTypes: { history },
const History = {

contextTypes: { history },

componentWillMount () {
this.history = this.context.history
}

componentWillMount () {
this.history = this.context.history
}

}
return History

export default History
}
19 changes: 11 additions & 8 deletions modules/IndexLink.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from 'react'
import Link from './Link'
import createLink from './Link'

const IndexLink = React.createClass({
export default function createIndexLink(React) {
const Link = createLink(React)

render() {
return <Link {...this.props} onlyActiveOnIndex={true} />
}
const IndexLink = React.createClass({

})
render() {
return <Link {...this.props} onlyActiveOnIndex={true} />
}

export default IndexLink
})

return IndexLink
}
85 changes: 45 additions & 40 deletions modules/IndexRoute.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
import React from 'react'
import invariant from 'invariant'
import warning from 'warning'
import { createRouteFromReactElement } from './RouteUtils'
import { component, components, falsy } from './PropTypes'

const { bool, func } = React.PropTypes

/**
* An <IndexRoute> is used to specify its parent's <Route indexRoute> in
* a JSX route config.
*/
const IndexRoute = React.createClass({

statics: {

createRouteFromReactElement(element, parentRoute) {
if (parentRoute) {
parentRoute.indexRoute = createRouteFromReactElement(element)
} else {
warning(
false,
'An <IndexRoute> does not make sense at the root of your route config'
)
import createRouteUtils from './RouteUtils'
import createPropTypes from './PropTypes'

export default function createIndexRoute(React) {
const { createRouteFromReactElement } = createRouteUtils(React)
const { component, components, falsy } = createPropTypes(React)

const { bool, func } = React.PropTypes

/**
* An <IndexRoute> is used to specify its parent's <Route indexRoute> in
* a JSX route config.
*/
const IndexRoute = React.createClass({

statics: {

createRouteFromReactElement(element, parentRoute) {
if (parentRoute) {
parentRoute.indexRoute = createRouteFromReactElement(element)
} else {
warning(
false,
'An <IndexRoute> does not make sense at the root of your route config'
)
}
}
}

},

propTypes: {
path: falsy,
ignoreScrollBehavior: bool,
component,
components,
getComponents: func
},
},

propTypes: {
path: falsy,
ignoreScrollBehavior: bool,
component,
components,
getComponents: func
},

render() {
invariant(
false,
'<IndexRoute> elements are for router configuration only and should not be rendered'
)
}

render() {
invariant(
false,
'<IndexRoute> elements are for router configuration only and should not be rendered'
)
}
})

})
return IndexRoute

export default IndexRoute
}
113 changes: 58 additions & 55 deletions modules/Lifecycle.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,72 @@
import React from 'react'
import invariant from 'invariant'

const { object } = React.PropTypes
export default function createLifecycle(React) {

/**
* The Lifecycle mixin adds the routerWillLeave lifecycle method
* to a component that may be used to cancel a transition or prompt
* the user for confirmation.
*
* On standard transitions, routerWillLeave receives a single argument: the
* location we're transitioning to. To cancel the transition, return false.
* To prompt the user for confirmation, return a prompt message (string).
*
* routerWillLeave does not receive a location object during the beforeunload
* event in web browsers (assuming you're using the useBeforeUnload history
* enhancer). In this case, it is not possible for us to know the location
* we're transitioning to so routerWillLeave must return a prompt message to
* prevent the user from closing the tab.
*/
const Lifecycle = {
const { object } = React.PropTypes

propTypes: {
// Route components receive the route object as a prop.
route: object
},
/**
* The Lifecycle mixin adds the routerWillLeave lifecycle method
* to a component that may be used to cancel a transition or prompt
* the user for confirmation.
*
* On standard transitions, routerWillLeave receives a single argument: the
* location we're transitioning to. To cancel the transition, return false.
* To prompt the user for confirmation, return a prompt message (string).
*
* routerWillLeave does not receive a location object during the beforeunload
* event in web browsers (assuming you're using the useBeforeUnload history
* enhancer). In this case, it is not possible for us to know the location
* we're transitioning to so routerWillLeave must return a prompt message to
* prevent the user from closing the tab.
*/
const Lifecycle = {

contextTypes: {
history: object.isRequired,
// Nested children receive the route as context, either
// set by the route component using the RouteContext mixin
// or by some other ancestor.
route: object
},
propTypes: {
// Route components receive the route object as a prop.
route: object
},

_getRoute() {
const route = this.props.route || this.context.route
contextTypes: {
history: object.isRequired,
// Nested children receive the route as context, either
// set by the route component using the RouteContext mixin
// or by some other ancestor.
route: object
},

invariant(
route,
'The Lifecycle mixin needs to be used either on 1) a <Route component> or ' +
'2) a descendant of a <Route component> that uses the RouteContext mixin'
)
_getRoute() {
const route = this.props.route || this.context.route

return route
},
invariant(
route,
'The Lifecycle mixin needs to be used either on 1) a <Route component> or ' +
'2) a descendant of a <Route component> that uses the RouteContext mixin'
)

componentWillMount() {
invariant(
this.routerWillLeave,
'The Lifecycle mixin requires you to define a routerWillLeave method'
)
return route
},

this.context.history.registerRouteHook(
this._getRoute(),
this.routerWillLeave
)
},
componentWillMount() {
invariant(
this.routerWillLeave,
'The Lifecycle mixin requires you to define a routerWillLeave method'
)

this.context.history.registerRouteHook(
this._getRoute(),
this.routerWillLeave
)
},

componentWillUnmount() {
this.context.history.unregisterRouteHook(
this._getRoute(),
this.routerWillLeave
)
}

componentWillUnmount() {
this.context.history.unregisterRouteHook(
this._getRoute(),
this.routerWillLeave
)
}

}
return Lifecycle

export default Lifecycle
}
Loading