From bb2ced764938c4aa6b4e003b7dedb26c8a096b97 Mon Sep 17 00:00:00 2001 From: Victor Chabbert Date: Sun, 28 May 2017 23:39:12 +0200 Subject: Initial type checking work with flowtype --- frontend/src/redux/games.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'frontend/src/redux/games.js') diff --git a/frontend/src/redux/games.js b/frontend/src/redux/games.js index d5953db1..f2df2492 100644 --- a/frontend/src/redux/games.js +++ b/frontend/src/redux/games.js @@ -1,5 +1,6 @@ +// @flow import { fromJS } from 'immutable'; -import GamesState from '../models/games'; +import GamesState, { type GameMapType, type GameNormalMapType, type GameShape } from '../models/games'; export const types = { UPDATE_GAMES: 'GAME/UPDATE_GAMES', @@ -10,19 +11,21 @@ export const types = { ENTER_GAME: 'GAME/ENTER_GAME', }; +type Actions = { type: 'GAME/UPDATE_GAMES', games: GameMapType } | { type: 'GAME/REQUEST_CREATE_GAME', gameId: string }; + export const actions = { - updateGames: games => ({ type: types.UPDATE_GAMES, games: fromJS(games) }), - requestJoinGame: gameId => ({ type: types.REQUEST_JOIN_GAME, gameId }), - requestCreateGame: gameName => ({ + updateGames: (games: GameNormalMapType) => ({ type: types.UPDATE_GAMES, games: fromJS(games) }), + requestJoinGame: (gameId: string) => ({ type: types.REQUEST_JOIN_GAME, gameId }), + requestCreateGame: (gameName: string) => ({ type: types.REQUEST_CREATE_GAME, gameName, }), requestStartGame: () => ({ type: types.REQUEST_START_GAME }), - enterLobby: lobby => ({ type: types.ENTER_LOBBY, lobby: fromJS(lobby) }), + enterLobby: (lobby: GameShape) => ({ type: types.ENTER_LOBBY, lobby: fromJS(lobby) }), enterGame: () => ({ type: types.ENTER_GAME }), }; -export default (state = new GamesState(), action) => { +export default (state: GamesState = new GamesState(), action: Actions) => { switch (action.type) { case types.UPDATE_GAMES: return state.addGames(action.games); -- cgit