123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- /** @module SZTMExcel */
- // Import dependencies
- import React from 'react'
- import ReactDOM from 'react-dom'
- import { createStore, combineReducers, bindActionCreators, compose } from 'redux'
- import { Provider, connect } from 'react-redux'
- /** react-router is not used in this project.
- import { browserHistory, Router, Route, IndexRoute } from 'react-router'
- import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
- */
- // Import the main app
- import Main from './Main'
- // Import the submodules
- import player from './player'
- import match from './match'
- /**
- * Redux Section
- */
- /** The root reducer is combined from all sub-module reducers */
- const rootReducer = combineReducers({
- player: player.reducer,
- match: match.reducer,
- })
- console.log('Root reducer:', rootReducer)
- /** The default state is combined from all sub-module states */
- const defaultState = {
- player: player.state,
- match: match.state,
- }
- console.log('Default state:', defaultState)
- /** The enhancer allows to use Redux development tools in Chrome */
- const enhancers = compose(
- window.devToolsExtension ? window.devToolsExtension() : f => f
- )
- console.log('Enhancers:', enhancers)
- /** Build the Redux store from the rootReducer, the defualtState and the enhancers. */
- const store = createStore(rootReducer, defaultState, enhancers)
- console.log('Store:', store)
- /** react-route is not used in this project.
- const history = syncHistoryWithStore(browserHistory, store)
- console.log('history:', history)
- */
- /** Collect the action creators from all modules in actionCreators */
- const actionCreators = {
- player: player.actions,
- match: match.actions,
- }
- /** Creates a function */
- function mapStateToProps (state) {
- const propState = {}
- Object.keys(state).forEach(key => {
- propState[key] = state[key]
- })
- console.log('Mapping state to props:', state, propState)
- return propState
- }
- function mapDispatchToProps (dispatch) {
- const boundActionCreators = {}
- console.log('ActionCreators', actionCreators)
- Object.keys(actionCreators).forEach(key => {
- boundActionCreators[`${key}Actions`] = bindActionCreators(actionCreators[key], dispatch)
- })
- console.log('Mapping dispatch to props:', dispatch, boundActionCreators)
- return boundActionCreators
- }
- const App = connect(mapStateToProps, mapDispatchToProps)(Main)
- /**
- * React-Router Section
- **/
- /** Combine the routes from all modules.
- const router = (
- <Provider store={store}>
- <Router history={history}>
- <Route component={App}>
- <Route path='/'>
- <IndexRoute component={demo_module.components.DemoModule} />
- <Route path='/project/:projectId' component={project.components.Project} />
- <Route path='/project' component={project.components.Project} />
- <Route path='/registermap/:registermapId' component={registermap.components.Registermap} />
- <Route path='/registermap' component={registermap.components.Registermap} />
- <Route path='/sample' component={Sample} />
- </Route>
- {demo_module.routes}
- <Route path='/login' />
- </Route>
- </Router>
- </Provider>
- )
- */
- const provider = (
- <Provider store={store}>
- <App />
- </Provider>
- )
- /**
- * Render the app
- **/
- ReactDOM.render(
- provider,
- document.getElementById('root')
- )
|