summaryrefslogtreecommitdiff
path: root/frontend/src/sagas
diff options
context:
space:
mode:
authorVictor Chabbert <chabbertvi@eisti.eu>2017-05-20 15:00:13 +0200
committerVictor Chabbert <chabbertvi@eisti.eu>2017-05-20 15:00:13 +0200
commit33e3b361d4e9758bbbab1d23ac6b51a2af21e781 (patch)
tree8670e3b4f4e76dc52a852a46d6c8170c982ec9f0 /frontend/src/sagas
parentFixed 'unused React' warning (diff)
downloadseven-wonders-33e3b361d4e9758bbbab1d23ac6b51a2af21e781.tar.gz
seven-wonders-33e3b361d4e9758bbbab1d23ac6b51a2af21e781.tar.bz2
seven-wonders-33e3b361d4e9758bbbab1d23ac6b51a2af21e781.zip
Upgrade react-scripts to 1.0.1
Diffstat (limited to 'frontend/src/sagas')
-rw-r--r--frontend/src/sagas/gameBrowser.js87
1 files changed, 54 insertions, 33 deletions
diff --git a/frontend/src/sagas/gameBrowser.js b/frontend/src/sagas/gameBrowser.js
index b12587ef..9f7e1565 100644
--- a/frontend/src/sagas/gameBrowser.js
+++ b/frontend/src/sagas/gameBrowser.js
@@ -1,64 +1,85 @@
-import { call, put, take, apply } from 'redux-saga/effects'
-import { createSubscriptionChannel } from '../utils/websocket'
-import { push } from 'react-router-redux'
+import { call, put, take, apply } from "redux-saga/effects";
+import { createSubscriptionChannel } from "../utils/websocket";
+import { push } from "react-router-redux";
-import { normalize } from 'normalizr'
-import { game as gameSchema, gameList as gameListSchema } from '../schemas/games'
+import { normalize } from "normalizr";
+import {
+ game as gameSchema,
+ gameList as gameListSchema
+} from "../schemas/games";
-import { actions as gameActions, types } from '../redux/games'
-import { actions as playerActions } from '../redux/players'
+import { actions as gameActions, types } from "../redux/games";
+import { actions as playerActions } from "../redux/players";
-function *watchGames({socket}) {
- const gamesChannel = yield call(createSubscriptionChannel, socket, '/topic/games')
+function* watchGames({ socket }) {
+ const gamesChannel = yield call(
+ createSubscriptionChannel,
+ socket,
+ "/topic/games"
+ );
try {
while (true) {
- const gameList = yield take(gamesChannel)
- const normGameList = normalize(gameList, gameListSchema)
+ const gameList = yield take(gamesChannel);
+ const normGameList = normalize(gameList, gameListSchema);
// for an empty game array, there is no players/games entity maps
- yield put(playerActions.updatePlayers(normGameList.entities.players || {}))
- yield put(gameActions.updateGames(normGameList.entities.games || {}))
+ yield put(
+ playerActions.updatePlayers(normGameList.entities.players || {})
+ );
+ yield put(gameActions.updateGames(normGameList.entities.games || {}));
}
} finally {
- yield apply(gamesChannel, gamesChannel.close)
+ yield apply(gamesChannel, gamesChannel.close);
}
}
-function *watchLobbyJoined({socket}) {
- const joinedLobbyChannel = yield call(createSubscriptionChannel, socket, '/user/queue/lobby/joined')
+function* watchLobbyJoined({ socket }) {
+ const joinedLobbyChannel = yield call(
+ createSubscriptionChannel,
+ socket,
+ "/user/queue/lobby/joined"
+ );
try {
- const joinedLobby = yield take(joinedLobbyChannel)
- const normalized = normalize(joinedLobby, gameSchema)
- const gameId = normalized.result
- yield put(playerActions.updatePlayers(normalized.entities.players))
- yield put(gameActions.updateGames(normalized.entities.games))
- yield put(gameActions.enterLobby(normalized.entities.games[gameId]))
- yield put(push(`/lobby/${gameId}`))
+ const joinedLobby = yield take(joinedLobbyChannel);
+ const normalized = normalize(joinedLobby, gameSchema);
+ const gameId = normalized.result;
+ yield put(playerActions.updatePlayers(normalized.entities.players));
+ yield put(gameActions.updateGames(normalized.entities.games));
+ yield put(gameActions.enterLobby(normalized.entities.games[gameId]));
+ yield put(push(`/lobby/${gameId}`));
} finally {
- yield apply(joinedLobbyChannel, joinedLobbyChannel.close)
+ yield apply(joinedLobbyChannel, joinedLobbyChannel.close);
}
}
-function *createGame({socket}) {
+function* createGame({ socket }) {
while (true) {
- const {gameName} = yield take(types.REQUEST_CREATE_GAME)
- yield apply(socket, socket.send, ['/app/lobby/create', JSON.stringify({gameName}), {}])
+ const { gameName } = yield take(types.REQUEST_CREATE_GAME);
+ yield apply(socket, socket.send, [
+ "/app/lobby/create",
+ JSON.stringify({ gameName }),
+ {}
+ ]);
}
}
-function *joinGame({socket}) {
+function* joinGame({ socket }) {
while (true) {
- const {gameId} = yield take(types.REQUEST_JOIN_GAME)
- yield apply(socket, socket.send, ['/app/lobby/join', JSON.stringify({gameId}), {}])
+ const { gameId } = yield take(types.REQUEST_JOIN_GAME);
+ yield apply(socket, socket.send, [
+ "/app/lobby/join",
+ JSON.stringify({ gameId }),
+ {}
+ ]);
}
}
-function *gameBrowserSaga(socketConnection) {
+function* gameBrowserSaga(socketConnection) {
yield [
call(watchGames, socketConnection),
call(watchLobbyJoined, socketConnection),
call(createGame, socketConnection),
call(joinGame, socketConnection)
- ]
+ ];
}
-export default gameBrowserSaga
+export default gameBrowserSaga;
bgstack15