summaryrefslogtreecommitdiff
path: root/frontend/src/redux/games.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/redux/games.js')
-rw-r--r--frontend/src/redux/games.js29
1 files changed, 11 insertions, 18 deletions
diff --git a/frontend/src/redux/games.js b/frontend/src/redux/games.js
index 9ef0e7cd..d5953db1 100644
--- a/frontend/src/redux/games.js
+++ b/frontend/src/redux/games.js
@@ -1,4 +1,5 @@
-import Immutable from 'seamless-immutable';
+import { fromJS } from 'immutable';
+import GamesState from '../models/games';
export const types = {
UPDATE_GAMES: 'GAME/UPDATE_GAMES',
@@ -10,37 +11,29 @@ export const types = {
};
export const actions = {
- updateGames: games => ({ type: types.UPDATE_GAMES, games: Immutable(games) }),
+ updateGames: games => ({ type: types.UPDATE_GAMES, games: fromJS(games) }),
requestJoinGame: gameId => ({ type: types.REQUEST_JOIN_GAME, gameId }),
requestCreateGame: gameName => ({
type: types.REQUEST_CREATE_GAME,
gameName,
}),
requestStartGame: () => ({ type: types.REQUEST_START_GAME }),
- enterLobby: lobby => ({ type: types.ENTER_LOBBY, lobby: Immutable(lobby) }),
+ enterLobby: lobby => ({ type: types.ENTER_LOBBY, lobby: fromJS(lobby) }),
enterGame: () => ({ type: types.ENTER_GAME }),
};
-const initialState = Immutable.from({
- all: {},
- current: '',
-});
-
-export default (state = initialState, action) => {
+export default (state = new GamesState(), action) => {
switch (action.type) {
case types.UPDATE_GAMES:
- return Immutable.merge(state, { all: action.games }, { deep: true });
+ return state.addGames(action.games);
case types.ENTER_LOBBY:
- return state.set('current', action.lobby.id);
+ return state.set('current', action.lobby.get('id'));
default:
return state;
}
};
-export const getAllGamesById = state => state.games.all;
-export const getAllGames = state => {
- let gamesById = getAllGamesById(state);
- return Object.keys(gamesById).map(k => gamesById[k]);
-};
-export const getGame = (state, id) => getAllGamesById(state)[id];
-export const getCurrentGame = state => getGame(state, state.games.current);
+export const getAllGamesById = games => games.all;
+export const getAllGames = games => getAllGamesById(games).toList();
+export const getGame = (games, id) => getAllGamesById(games).get(`${id}`);
+export const getCurrentGame = games => getGame(games, games.current);
bgstack15