blob: 4115323c49d3e85dea6e313318162a494c2d885d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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.CREATE_OR_UPDATE_GAMES:
return state.mergeDeep(action.games)
default:
return state
}
}
export const getAllGames = state => state.get('games')
|