This repository has been archived by the owner on Apr 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
/
render.js
80 lines (68 loc) · 2.04 KB
/
render.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react'
import { render } from 'react-dom'
import { Router as ReactRouter, browserHistory, hashHistory, createMemoryHistory } from 'react-router'
import { Provider } from 'react-redux'
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
import { combine } from './reducer'
import Component from './component'
export let syncedHistory
export default function (stores, baseComponent, options = {}) {
const store = combine({
...stores,
routing: routerReducer
}, options)
if (typeof baseComponent === 'function') {
baseComponent = baseComponent(store)
}
let history
if (global.IS_SERVERSIDE) {
history = createMemoryHistory()
} else {
history = options.useHash ? hashHistory : browserHistory
}
syncedHistory = syncHistoryWithStore(history, store)
const base = baseComponent
let WrappedBaseComponent
if (process.env.NODE_ENV !== 'production') {
if (global.devToolsExtension) {
console.warn('Jumpsuit doesn\'t support the Redux Dev Tools browser extension!')
}
const Hsr = process.env.HSR_WS ? require('./hsr').default : () => <div />
const DevTools = require('./devtools').default
WrappedBaseComponent = Component({
getInitialState: () => ({
ready: !process.env.HSR_WS
}),
render () {
return (
<div>
{this.state.ready ? base : <span />}
<DevTools />
<Hsr onReady={() => this.setState({ready: true})} />
</div>
)
}
})
}
const root = (
<Provider store={store}>
{WrappedBaseComponent ? <WrappedBaseComponent /> : base}
</Provider>
)
global.document && render(
root,
global.document.getElementById(options.root || 'app')
)
return root
}
export const Router = React.createClass({
propTypes: { children: React.PropTypes.object },
getDefaultProps: () => ({ _isRouteWrapper: true }),
render: function () {
return (
<ReactRouter history={syncedHistory}>
{this.props.children}
</ReactRouter>
)
}
})