summaryrefslogtreecommitdiff
path: root/frontend/src
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src')
-rw-r--r--frontend/src/containers/gameBrowser.js4
-rw-r--r--frontend/src/index.js1
-rw-r--r--frontend/src/reducers.js21
-rw-r--r--frontend/src/redux/app.js15
-rw-r--r--frontend/src/store.js8
5 files changed, 42 insertions, 7 deletions
diff --git a/frontend/src/containers/gameBrowser.js b/frontend/src/containers/gameBrowser.js
index bc3933fa..11cadcf6 100644
--- a/frontend/src/containers/gameBrowser.js
+++ b/frontend/src/containers/gameBrowser.js
@@ -40,8 +40,8 @@ class App extends Component {
}
const mapStateToProps = (state) => ({
- username: state.players.get('all').get(state.players.get('current')).get('displayName'),
- games: state.games
+ username: state.get('players').get('all').get(state.get('players').get('current')).get('displayName'),
+ games: state.get('games')
})
diff --git a/frontend/src/index.js b/frontend/src/index.js
index 1959b14a..08f257f3 100644
--- a/frontend/src/index.js
+++ b/frontend/src/index.js
@@ -4,6 +4,7 @@ import React from 'react'
import ReactDOM from 'react-dom'
import { Router } from 'react-router'
import { Provider } from 'react-redux'
+
import configureStore from './store'
import { routes } from './routes'
diff --git a/frontend/src/reducers.js b/frontend/src/reducers.js
index 9befff13..097f9243 100644
--- a/frontend/src/reducers.js
+++ b/frontend/src/reducers.js
@@ -1,5 +1,20 @@
-import { combineReducers } from 'redux'
-import { routerReducer } from 'react-router-redux'
+import { combineReducers } from 'redux-immutable'
+
+// react-router-redux immutable reducer
+import { fromJS } from 'immutable'
+import { LOCATION_CHANGE } from 'react-router-redux'
+
+const initialState = fromJS({
+ locationBeforeTransitions: null
+})
+
+const routerImmutableReducer = (state = initialState, action) => {
+ if (action.type === LOCATION_CHANGE) {
+ return state.set('locationBeforeTransitions', action.payload)
+ }
+
+ return state
+}
import gamesReducer from './redux/games'
import playersReducer from './redux/players'
@@ -7,7 +22,7 @@ import playersReducer from './redux/players'
export default function createReducer() {
return combineReducers({
games: gamesReducer,
- routing: routerReducer,
+ routing: routerImmutableReducer,
players: playersReducer,
})
}
diff --git a/frontend/src/redux/app.js b/frontend/src/redux/app.js
new file mode 100644
index 00000000..172dc960
--- /dev/null
+++ b/frontend/src/redux/app.js
@@ -0,0 +1,15 @@
+export const makeSelectLocationState = () => {
+ let prevRoutingState;
+ let prevRoutingStateJS;
+
+ return (state) => {
+ const routingState = state.get('routing')
+
+ if (!routingState.equals(prevRoutingState)) {
+ prevRoutingState = routingState
+ prevRoutingStateJS = routingState.toJS()
+ }
+
+ return prevRoutingStateJS;
+ }
+}
diff --git a/frontend/src/store.js b/frontend/src/store.js
index e028bac1..2000d706 100644
--- a/frontend/src/store.js
+++ b/frontend/src/store.js
@@ -1,10 +1,12 @@
import { createStore, applyMiddleware, compose } from 'redux'
import { browserHistory } from 'react-router'
import { syncHistoryWithStore, routerMiddleware } from 'react-router-redux'
+import { fromJS } from 'immutable'
import createReducer from './reducers'
import createSagaMiddleware from 'redux-saga'
import rootSaga from './sagas'
+import { makeSelectLocationState } from './redux/app'
export default function configureStore(initialState = {}) {
const sagaMiddleware = createSagaMiddleware()
@@ -26,7 +28,7 @@ export default function configureStore(initialState = {}) {
const store = createStore(
createReducer(),
- initialState,
+ fromJS(initialState),
composeEnhancers(...enhancers)
)
@@ -34,6 +36,8 @@ export default function configureStore(initialState = {}) {
return {
store,
- history: syncHistoryWithStore(browserHistory, store)
+ history: syncHistoryWithStore(browserHistory, store, {
+ selectLocationState: makeSelectLocationState()
+ })
}
}
bgstack15