summaryrefslogtreecommitdiff
path: root/frontend/src/redux/games.js
diff options
context:
space:
mode:
authorVictor Chabbert <chabbertvi@eisti.eu>2017-01-22 14:48:24 +0100
committerVictor Chabbert <chabbertvi@eisti.eu>2017-01-22 14:48:37 +0100
commit7b6230dc1c2613b965f4ff21836432076248dfde (patch)
tree83d8732ce9f87104faf4c6789c79d1d74dc6b575 /frontend/src/redux/games.js
parentRefactor user reducer to player reducer (diff)
downloadseven-wonders-7b6230dc1c2613b965f4ff21836432076248dfde.tar.gz
seven-wonders-7b6230dc1c2613b965f4ff21836432076248dfde.tar.bz2
seven-wonders-7b6230dc1c2613b965f4ff21836432076248dfde.zip
Normalize games data from server and display games list
Diffstat (limited to 'frontend/src/redux/games.js')
-rw-r--r--frontend/src/redux/games.js29
1 files changed, 29 insertions, 0 deletions
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
+ }
+}
bgstack15