-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use createElement instead of root route * Support per-route render callbacks
- Loading branch information
Showing
15 changed files
with
404 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"stage": 0, | ||
"loose": "all" | ||
"loose": "all", | ||
"optional": ["runtime"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,3 @@ | ||
{ | ||
"extends": "eslint-config-airbnb", | ||
"env": { | ||
"browser": true, | ||
"mocha": true, | ||
"node": true | ||
}, | ||
"rules": { | ||
"react/jsx-uses-react": 2, | ||
"react/jsx-uses-vars": 2, | ||
"react/react-in-jsx-scope": 2 | ||
}, | ||
"plugins": [ | ||
"react" | ||
] | ||
"extends": "airbnb" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react'; | ||
import StaticContainer from 'react-static-container'; | ||
|
||
import getParamsForRoute from './getParamsForRoute'; | ||
import RootComponent from './RootComponent'; | ||
import RouteAggregator from './RouteAggregator'; | ||
|
||
export default class Container extends React.Component { | ||
static displayName = 'ReactRouterRelay.Container'; | ||
|
||
static propTypes = { | ||
Component: React.PropTypes.func.isRequired, | ||
routerProps: React.PropTypes.object.isRequired, | ||
}; | ||
|
||
static contextTypes = { | ||
routeAggregator: React.PropTypes.instanceOf(RouteAggregator), | ||
}; | ||
|
||
render() { | ||
const {routeAggregator} = this.context; | ||
if (!routeAggregator) { | ||
return <RootComponent {...this.props} />; | ||
} | ||
|
||
const {Component, routerProps} = this.props; | ||
const {route} = routerProps; | ||
|
||
// FIXME: Remove once fix for facebook/react#4218 is released. | ||
const {children} = routerProps; | ||
if (children) { | ||
routerProps.children = React.cloneElement(children, {}); | ||
} | ||
|
||
const {queries} = route; | ||
if (!queries) { | ||
return <Component {...routerProps} />; | ||
} | ||
|
||
const params = getParamsForRoute(routerProps); | ||
const {fragmentPointers, failure} = | ||
routeAggregator.getData(queries, params); | ||
|
||
let shouldUpdate = true; | ||
let element; | ||
|
||
// This is largely copied from RelayRootContainer#render. | ||
if (failure) { | ||
const {renderFailure} = route; | ||
if (renderFailure) { | ||
const [error, retry] = failure; | ||
element = renderFailure(error, retry); | ||
} else { | ||
element = null; | ||
} | ||
} else if (fragmentPointers) { | ||
const data = {...routerProps, ...params, ...fragmentPointers}; | ||
|
||
const {renderFetched} = route; | ||
if (renderFetched) { | ||
element = renderFetched(data); | ||
} else { | ||
element = <Component {...data} />; | ||
} | ||
} else { | ||
const {renderLoading} = route; | ||
if (renderLoading) { | ||
element = renderLoading(); | ||
} else { | ||
element = undefined; | ||
} | ||
|
||
if (element === undefined) { | ||
element = null; | ||
shouldUpdate = false; | ||
} | ||
} | ||
|
||
return ( | ||
<StaticContainer shouldUpdate={shouldUpdate}> | ||
{element} | ||
</StaticContainer> | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import Relay from 'react-relay'; | ||
|
||
import Container from './Container'; | ||
import RouteAggregator from './RouteAggregator'; | ||
|
||
export default class RootComponent extends React.Component { | ||
static displayName = 'ReactRouterRelay.RootComponent'; | ||
|
||
static propTypes = { | ||
routerProps: React.PropTypes.object.isRequired, | ||
}; | ||
|
||
static childContextTypes = { | ||
routeAggregator: React.PropTypes.instanceOf(RouteAggregator).isRequired, | ||
}; | ||
|
||
constructor(props, context) { | ||
super(props, context); | ||
|
||
this._routeAggregator = new RouteAggregator(); | ||
this._routeAggregator.updateRoute(props.routerProps); | ||
} | ||
|
||
getChildContext() { | ||
return { | ||
routeAggregator: this._routeAggregator, | ||
}; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
const {routerProps} = nextProps; | ||
if (routerProps.isTransitioning) { | ||
return; | ||
} | ||
|
||
this._routeAggregator.updateRoute(routerProps); | ||
} | ||
|
||
renderLoading = () => { | ||
this._routeAggregator.setLoading(); | ||
return this.renderComponent(); | ||
}; | ||
|
||
renderFetched = (data) => { | ||
this._routeAggregator.setFetched(data); | ||
return this.renderComponent(); | ||
}; | ||
|
||
renderFailure = (error, retry) => { | ||
this._routeAggregator.setFailure(error, retry); | ||
return this.renderComponent(); | ||
}; | ||
|
||
renderComponent() { | ||
return <Container {...this.props} />; | ||
} | ||
|
||
render() { | ||
return ( | ||
<Relay.RootContainer | ||
Component={this._routeAggregator} | ||
route={this._routeAggregator.route} | ||
renderLoading={this.renderLoading} | ||
renderFetched={this.renderFetched} | ||
renderFailure={this.renderFailure} | ||
/> | ||
); | ||
} | ||
} |
Oops, something went wrong.