|
@@ -3,8 +3,11 @@
|
|
|
// Import dependencies
|
|
|
import React from 'react'
|
|
|
import ReactDOM from 'react-dom'
|
|
|
-import { createStore, combineReducers, bindActionCreators, compose } from 'redux'
|
|
|
+import { createStore, applyMiddleware, combineReducers, bindActionCreators, compose } from 'redux'
|
|
|
import { Provider, connect } from 'react-redux'
|
|
|
+import createSagaMiddleware from 'redux-saga'
|
|
|
+import { all } from 'redux-saga/effects'
|
|
|
+
|
|
|
/** react-router is not used in this project.
|
|
|
import { browserHistory, Router, Route, IndexRoute } from 'react-router'
|
|
|
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
|
|
@@ -14,8 +17,10 @@ import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
|
|
|
import Main from './Main'
|
|
|
|
|
|
// Import the submodules
|
|
|
-import player from './player'
|
|
|
-import match from './match'
|
|
|
+import playerList from './playerList'
|
|
|
+import matchList from './matchList'
|
|
|
+import layout from './layout'
|
|
|
+import alerts from './alerts'
|
|
|
|
|
|
/**
|
|
|
* Redux Section
|
|
@@ -23,26 +28,46 @@ import match from './match'
|
|
|
|
|
|
/** The root reducer is combined from all sub-module reducers */
|
|
|
const rootReducer = combineReducers({
|
|
|
- player: player.reducer,
|
|
|
- match: match.reducer
|
|
|
+ playerList: playerList.reducer,
|
|
|
+ matchList: matchList.reducer,
|
|
|
+ layout: layout.reducer,
|
|
|
+ alerts: alerts.reducer
|
|
|
})
|
|
|
console.log('Root reducer:', rootReducer)
|
|
|
|
|
|
/** The default state is combined from all sub-module states */
|
|
|
const defaultState = {
|
|
|
- player: player.state,
|
|
|
- match: match.state
|
|
|
+ playerList: playerList.state,
|
|
|
+ matchList: matchList.state,
|
|
|
+ layout: layout.state,
|
|
|
+ alerts: alerts.state
|
|
|
}
|
|
|
console.log('Default state:', defaultState)
|
|
|
|
|
|
+/** The root saga, calling all other sagas */
|
|
|
+function * rootSaga () {
|
|
|
+ console.log('rootSaga called')
|
|
|
+ yield all([
|
|
|
+ playerList.saga(),
|
|
|
+ matchList.saga(),
|
|
|
+ layout.saga(),
|
|
|
+ alerts.saga()
|
|
|
+ ])
|
|
|
+}
|
|
|
+
|
|
|
+/** Create the saga middleware */
|
|
|
+const sagaMiddleware = createSagaMiddleware()
|
|
|
+
|
|
|
/** The enhancer allows to use Redux development tools in Chrome */
|
|
|
const enhancers = compose(
|
|
|
+ applyMiddleware(sagaMiddleware),
|
|
|
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)
|
|
|
+sagaMiddleware.run(rootSaga)
|
|
|
console.log('Store:', store)
|
|
|
/** react-route is not used in this project.
|
|
|
const history = syncHistoryWithStore(browserHistory, store)
|
|
@@ -51,8 +76,10 @@ console.log('history:', history)
|
|
|
|
|
|
/** Collect the action creators from all modules in actionCreators */
|
|
|
const actionCreators = {
|
|
|
- player: player.actions,
|
|
|
- match: match.actions
|
|
|
+ playerList: playerList.actions,
|
|
|
+ matchList: matchList.actions,
|
|
|
+ layout: layout.actions,
|
|
|
+ alerts: alerts.actions
|
|
|
}
|
|
|
|
|
|
/** Creates a function */
|
|
@@ -101,7 +128,6 @@ const router = (
|
|
|
</Provider>
|
|
|
)
|
|
|
*/
|
|
|
-
|
|
|
const provider = (
|
|
|
<Provider store={store}>
|
|
|
<App />
|