Skip to content

Commit

Permalink
Add new API to let people wrap the root component
Browse files Browse the repository at this point in the history
E.g. for adding Redux support.
  • Loading branch information
KyleAMathews committed Oct 11, 2016
1 parent 2c48e5c commit ebd57d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 12 additions & 7 deletions lib/intermediate-representation-dir/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ apiRunner('clientEntry')

import React from 'react'
import ReactDOM from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import { AppContainer as HotContainer } from 'react-hot-loader'

const rootElement = document.getElementById(`react-mount`)
let Root = require('./root')
if (Root.default) { Root = Root.default }

// Let site, plugins wrap the site e.g. for Redux.
const NewRoot = apiRunner('wrapRootComponent', { Root: Root }, Root)
ReactDOM.render(
<AppContainer>
<Root />
</AppContainer>,
<HotContainer>
<NewRoot />
</HotContainer>,
rootElement
)

if (module.hot) {
module.hot.accept(`./root`, () => {
let NextRoot = require('./root')
if (NextRoot.default) { NextRoot = NextRoot.default }
// Let site, plugins wrap the site e.g. for Redux.
const NewRoot = apiRunner('wrapRootComponent', { Root: NextRoot }, NextRoot)
ReactDOM.render(
<AppContainer>
<NextRoot />
</AppContainer>,
<HotContainer>
<NewRoot />
</HotContainer>,
rootElement
)
})
Expand Down
6 changes: 5 additions & 1 deletion lib/intermediate-representation-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ function shouldUpdateScroll (prevRouterProps, { location: { pathname } }) {
}

match({ history: browserHistory, routes: rootRoute }, (error, redirectLocation, renderProps) => {
ReactDOM.render((
const Root = () => (
<Router
{...renderProps}
render={applyRouterMiddleware(useScroll(shouldUpdateScroll))}
onUpdate={() => {apiRunner('onRouteUpdate', currentLocation)}}
/>
)
const NewRoot = apiRunner('wrapRootComponent', { Root: Root }, Root)
ReactDOM.render((
<NewRoot />
), typeof window !== `undefined` ? document.getElementById(`react-mount`) : void 0)
})

0 comments on commit ebd57d2

Please sign in to comment.