-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
34 lines (31 loc) · 1.08 KB
/
client.js
File metadata and controls
34 lines (31 loc) · 1.08 KB
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
import React from 'react'
import ReactDOM from "react-dom"
import routes from './routes.js'
import { Router, browserHistory } from "react-router"
import { Provider } from 'react-redux'
import reducer from './reducers'
import { syncHistoryWithStore } from 'react-router-redux';
import configStore from './configStore'
const initialState = window.__INITIAL_STATE__
const store = configStore(initialState, browserHistory)
const history = syncHistoryWithStore(browserHistory, store)
function onUpdate() {
if (window.__INITIAL_STATE__ !== null) {
window.__INITIAL_STATE__ = null;
return
}
const { routes } = this.state
const defaultDataHandler = () => Promise.resolve()
const matchedRoute = routes[routes.length - 1]
const fetchDataHandler = matchedRoute.component
&& matchedRoute.component.fetchData || defaultDataHandler
fetchDataHandler(store.dispatch)
}
((window, document) => {
ReactDOM.render(
<Provider store={store}>
<Router history={history} routes={routes} onUpdate={onUpdate}/>
</Provider>,
document.getElementById('app')
)
})(window, document)