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'
|
|
|
|
import * as localStore from './localStore'
|
|
|
|
|
|
|
|
import * as reducers from './reducers'
|
|
|
|
|
|
|
|
import Main from './components/Main'
|
2016-11-28 18:47:47 +01:00
|
|
|
import Compare from './components/Compare'
|
|
|
|
|
|
|
|
import { Router } from 'react-router'
|
|
|
|
import createBrowserHistory from 'history/lib/createBrowserHistory'
|
|
|
|
import {Route, IndexRoute, Redirect } from 'react-router'
|
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()}>
|
|
|
|
<Route path="/" component={Main} />
|
|
|
|
<Route path="/**" component={Compare}/>
|
|
|
|
</Router>
|
2016-11-23 22:58:48 +01:00
|
|
|
</Provider>
|
|
|
|
, document.getElementById('root'))
|
|
|
|
}
|
|
|
|
|
|
|
|
render()
|
|
|
|
|