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, 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