summaryrefslogtreecommitdiff
path: root/frontend/src
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2018-04-30 00:34:13 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2018-04-30 00:38:46 +0200
commit5dd96bd91cbdc916b4bf758a6434d797393294ee (patch)
treeb4f678bb6ae242f1e0f67f8efc00a241958a1375 /frontend/src
parentFix sagas types (diff)
downloadseven-wonders-5dd96bd91cbdc916b4bf758a6434d797393294ee.tar.gz
seven-wonders-5dd96bd91cbdc916b4bf758a6434d797393294ee.tar.bz2
seven-wonders-5dd96bd91cbdc916b4bf758a6434d797393294ee.zip
Complete redux action types
Diffstat (limited to 'frontend/src')
-rw-r--r--frontend/src/redux/games.js36
-rw-r--r--frontend/src/redux/players.js19
2 files changed, 35 insertions, 20 deletions
diff --git a/frontend/src/redux/games.js b/frontend/src/redux/games.js
index 22b0d6bc..c6c13504 100644
--- a/frontend/src/redux/games.js
+++ b/frontend/src/redux/games.js
@@ -8,28 +8,36 @@ export const types = {
UPDATE_GAMES: 'GAMES/UPDATE_GAMES',
REQUEST_CREATE_GAME: 'GAMES/REQUEST_CREATE_GAME',
REQUEST_JOIN_GAME: 'GAMES/REQUEST_JOIN_GAME',
- REQUEST_START_GAME: 'GAMES/REQUEST_JOIN_GAME',
+ REQUEST_START_GAME: 'GAMES/REQUEST_START_GAME',
ENTER_LOBBY: 'GAMES/ENTER_LOBBY',
ENTER_GAME: 'GAMES/ENTER_GAME',
};
-type Actions =
- | { type: "GAMES/UPDATE_GAMES", games: GameMapType }
- | { type: "GAMES/REQUEST_CREATE_GAME", gameId: string };
+export type UpdateGamesAction = { type: 'GAMES/UPDATE_GAMES', games: GameMapType };
+export type RequestCreateGameAction = { type: 'GAMES/REQUEST_CREATE_GAME', gameName: string };
+export type RequestJoinGameAction = { type: 'GAMES/REQUEST_JOIN_GAME', gameId: string };
+export type RequestStartGameAction = { type: 'GAMES/REQUEST_START_GAME' };
+export type EnterLobbyAction = { type: 'GAMES/ENTER_LOBBY', lobby: GameShape };
+export type EnterGameAction = { type: 'GAMES/ENTER_GAME' };
+
+export type GamesAction =
+ | UpdateGamesAction
+ | RequestCreateGameAction
+ | RequestJoinGameAction
+ | RequestStartGameAction
+ | EnterLobbyAction
+ | EnterGameAction;
export const actions = {
- 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: GameShape) => ({ type: types.ENTER_LOBBY, lobby: fromJS(lobby) }),
- enterGame: () => ({ type: types.ENTER_GAME }),
+ updateGames: (games: GameNormalMapType): UpdateGamesAction => ({ type: types.UPDATE_GAMES, games: fromJS(games) }),
+ requestJoinGame: (gameId: string): RequestJoinGameAction => ({ type: types.REQUEST_JOIN_GAME, gameId }),
+ requestCreateGame: (gameName: string): RequestCreateGameAction => ({ type: types.REQUEST_CREATE_GAME, gameName }),
+ requestStartGame: (): RequestStartGameAction => ({ type: types.REQUEST_START_GAME }),
+ enterLobby: (lobby: GameShape): EnterLobbyAction => ({ type: types.ENTER_LOBBY, lobby: fromJS(lobby) }),
+ enterGame: (): EnterGameAction => ({ type: types.ENTER_GAME }),
};
-export const gamesReducer = (state: GamesState = new GamesState(), action: Actions) => {
+export const gamesReducer = (state: GamesState = new GamesState(), action: GamesAction) => {
switch (action.type) {
case types.UPDATE_GAMES:
return state.addGames(action.games);
diff --git a/frontend/src/redux/players.js b/frontend/src/redux/players.js
index de68ae13..1d6da562 100644
--- a/frontend/src/redux/players.js
+++ b/frontend/src/redux/players.js
@@ -1,4 +1,5 @@
-import { Player, PlayerState } from '../models/players';
+import { Map } from 'immutable';
+import { Player, PlayerShape, PlayerState } from '../models/players';
export const types = {
REQUEST_CHOOSE_USERNAME: 'USER/REQUEST_CHOOSE_USERNAME',
@@ -6,22 +7,28 @@ export const types = {
UPDATE_PLAYERS: 'USER/UPDATE_PLAYERS',
};
+export type RequestChooseUsernameAction = { type: types.REQUEST_CHOOSE_USERNAME, username: string };
+export type SetCurrentPlayerAction = { type: types.SET_CURRENT_PLAYER, player: PlayerShape };
+export type UpdatePlayersAction = { type: types.UPDATE_PLAYERS, players: Map<string, PlayerShape> };
+
+export type PlayerAction = RequestChooseUsernameAction | SetCurrentPlayerAction | UpdatePlayersAction;
+
export const actions = {
- chooseUsername: username => ({
+ chooseUsername: (username: string): RequestChooseUsernameAction => ({
type: types.REQUEST_CHOOSE_USERNAME,
username,
}),
- setCurrentPlayer: player => ({
+ setCurrentPlayer: (player: PlayerShape): SetCurrentPlayerAction => ({
type: types.SET_CURRENT_PLAYER,
player,
}),
- updatePlayers: players => ({
+ updatePlayers: (players: Map<string, PlayerShape>): UpdatePlayersAction => ({
type: types.UPDATE_PLAYERS,
players,
}),
};
-export const playersReducer = (state = new PlayerState(), action) => {
+export const playersReducer = (state = new PlayerState(), action: PlayerAction) => {
switch (action.type) {
case types.SET_CURRENT_PLAYER:
return state.addPlayer(action.player);
@@ -32,6 +39,6 @@ export const playersReducer = (state = new PlayerState(), action) => {
}
};
-export const getCurrentPlayer = players => players.all.get(players.current, new Player({ displayName: '[ERROR]' }));
+export const getCurrentPlayer = players => players.all.get(players.current, new Player({displayName: '[ERROR]'}));
export const getPlayer = (players, username) => players.all.get(username);
export const getPlayers = (players, usernames) => usernames.map(u => getPlayer(players, u));
bgstack15