From 7b6230dc1c2613b965f4ff21836432076248dfde Mon Sep 17 00:00:00 2001 From: Victor Chabbert Date: Sun, 22 Jan 2017 14:48:24 +0100 Subject: Normalize games data from server and display games list --- frontend/src/redux/games.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 frontend/src/redux/games.js (limited to 'frontend/src/redux/games.js') diff --git a/frontend/src/redux/games.js b/frontend/src/redux/games.js new file mode 100644 index 00000000..4d393317 --- /dev/null +++ b/frontend/src/redux/games.js @@ -0,0 +1,29 @@ +import { Map } from 'immutable' + +export const types = { + CREATE_OR_UPDATE_GAMES: 'GAME/CREATE_OR_UPDATE_GAMES', + ENTER_GAME: 'GAME/ENTER_GAME', + JOIN_GAME: 'GAME/JOIN_GAME', + CREATE_GAME: 'GAME/CREATE_GAME', +} + +export const actions = { + createOrUpdateGame: (games) => ({ type: types.CREATE_OR_UPDATE_GAMES, games }), + enterGame: (username) => ({ type: types.ENTER_GAME, username }), + joinGame: (id) => ({ type: types.JOIN_GAME, id }), + createGame: (name) => ({ type: types.CREATE_GAME, name }), +} + + +const initialState = Map({}) + +export default (state = initialState, action) => { + switch (action.type) { + case types.NEW_GAME: + return state.set(action.game.get('id'), action.game) + case types.CREATE_OR_UPDATE_GAMES: + return state.mergeDeep(action.games) + default: + return state + } +} -- cgit