2016-11-23 22:58:48 +01:00
|
|
|
import React from 'react'
|
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
|
|
|
|
import * as Redux from 'redux'
|
|
|
|
|
|
|
|
import {Provider} from 'react-redux'
|
|
|
|
|
2016-11-28 18:47:47 +01:00
|
|
|
import createBrowserHistory from 'history/lib/createBrowserHistory'
|
2016-12-04 04:14:15 +01:00
|
|
|
import {Router, Route, IndexRoute, Redirect } from 'react-router'
|
|
|
|
|
|
|
|
import * as localStore from '../common/localStore'
|
|
|
|
import * as reducers from '../common/reducers'
|
|
|
|
import routes from '../common/routes'
|
2016-11-23 22:58:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
//create the redux store
|
|
|
|
//initial state is retrieved from localStore
|
|
|
|
const store = Redux.createStore(
|
|
|
|
Redux.combineReducers(reducers),
|
2016-11-28 18:47:47 +01:00
|
|
|
localStore.get("dubdiff"),
|
2016-11-23 22:58:48 +01:00
|
|
|
window.devToolsExtension ? window.devToolsExtension() : undefined
|
|
|
|
)
|
|
|
|
|
|
|
|
//save the state whenever the state changes
|
|
|
|
function saveState() {
|
|
|
|
let state = store.getState()
|
|
|
|
//pass the elements of state that should be persisted to the local store as an array of element name strings
|
2016-11-28 18:47:47 +01:00
|
|
|
localStore.set(state, ["input"], "dubdiff")
|
2016-11-23 22:58:48 +01:00
|
|
|
}
|
|
|
|
store.subscribe(saveState)
|
|
|
|
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
ReactDOM.render(
|
|
|
|
<Provider store={store}>
|
2016-11-28 18:47:47 +01:00
|
|
|
<Router history={createBrowserHistory()}>
|
2016-12-04 04:14:15 +01:00
|
|
|
{routes}
|
2016-11-28 18:47:47 +01:00
|
|
|
</Router>
|
2016-11-23 22:58:48 +01:00
|
|
|
</Provider>
|
|
|
|
, document.getElementById('root'))
|
|
|
|
}
|
|
|
|
|
|
|
|
render()
|
|
|
|
|