summaryrefslogtreecommitdiff
path: root/frontend/src/sagas
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/sagas')
-rw-r--r--frontend/src/sagas/gameBrowser.js12
-rw-r--r--frontend/src/sagas/home.js3
-rw-r--r--frontend/src/sagas/lobby.js5
-rw-r--r--frontend/src/sagas/utils.js10
4 files changed, 24 insertions, 6 deletions
diff --git a/frontend/src/sagas/gameBrowser.js b/frontend/src/sagas/gameBrowser.js
index 17eb9287..871908f6 100644
--- a/frontend/src/sagas/gameBrowser.js
+++ b/frontend/src/sagas/gameBrowser.js
@@ -8,9 +8,10 @@ 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 type { SevenWondersSession } from '../api/sevenWondersApi';
+import { createChannel } from './utils';
function* watchGames(session: SevenWondersSession): * {
- const gamesChannel = yield apply(session, session.watchGames, []);
+ const gamesChannel = yield createChannel(session, session.watchGames);
try {
while (true) {
const gameList = yield take(gamesChannel);
@@ -25,7 +26,7 @@ function* watchGames(session: SevenWondersSession): * {
}
function* watchLobbyJoined(session: SevenWondersSession): * {
- const joinedLobbyChannel = yield apply(session, session.watchLobbyJoined, []);
+ const joinedLobbyChannel = yield createChannel(session, session.watchLobbyJoined);
try {
const joinedLobby = yield take(joinedLobbyChannel);
const normalized = normalize(joinedLobby, gameSchema);
@@ -54,7 +55,12 @@ function* joinGame(session: SevenWondersSession): * {
}
function* gameBrowserSaga(session: SevenWondersSession): * {
- yield [call(watchGames, session), call(watchLobbyJoined, session), call(createGame, session), call(joinGame, session)];
+ yield [
+ call(watchGames, session),
+ call(watchLobbyJoined, session),
+ call(createGame, session),
+ call(joinGame, session),
+ ];
}
export default gameBrowserSaga;
diff --git a/frontend/src/sagas/home.js b/frontend/src/sagas/home.js
index eb65097b..b51bf4dc 100644
--- a/frontend/src/sagas/home.js
+++ b/frontend/src/sagas/home.js
@@ -3,6 +3,7 @@ import { push } from 'react-router-redux';
import { actions, types } from '../redux/players';
import type { SevenWondersSession } from '../api/sevenWondersApi';
+import { createChannel } from './utils';
function* sendUsername(session: SevenWondersSession) {
while (true) {
@@ -12,7 +13,7 @@ function* sendUsername(session: SevenWondersSession) {
}
function* validateUsername(session: SevenWondersSession) {
- const usernameChannel = yield apply(session, session.watchNameChoice, []);
+ const usernameChannel = yield createChannel(session, session.watchNameChoice);
while (true) {
const user = yield take(usernameChannel);
yield put(actions.setCurrentPlayer(user));
diff --git a/frontend/src/sagas/lobby.js b/frontend/src/sagas/lobby.js
index 0c264dde..cc704086 100644
--- a/frontend/src/sagas/lobby.js
+++ b/frontend/src/sagas/lobby.js
@@ -9,6 +9,7 @@ import { game as gameSchema } from '../schemas/games';
import { actions as gameActions, types } from '../redux/games';
import { actions as playerActions } from '../redux/players';
import { SevenWondersSession } from '../api/sevenWondersApi';
+import { createChannel } from './utils';
function getCurrentGameId(): number {
const path = window.location.pathname;
@@ -17,7 +18,7 @@ function getCurrentGameId(): number {
function* watchLobbyUpdates(session: SevenWondersSession) {
const currentGameId: number = getCurrentGameId();
- const lobbyUpdatesChannel: Channel = yield apply(session, session.watchLobbyUpdated, [currentGameId]);
+ const lobbyUpdatesChannel: Channel = yield createChannel(session, session.watchLobbyUpdated, currentGameId);
try {
while (true) {
const lobby = yield take(lobbyUpdatesChannel);
@@ -32,7 +33,7 @@ function* watchLobbyUpdates(session: SevenWondersSession) {
function* watchGameStart(session: SevenWondersSession) {
const currentGameId = getCurrentGameId();
- const gameStartedChannel = yield apply(session, session.watchGameStarted, [currentGameId]);
+ const gameStartedChannel = yield createChannel(session, session.watchGameStarted, currentGameId);
try {
yield take(gameStartedChannel);
yield put(gameActions.enterGame());
diff --git a/frontend/src/sagas/utils.js b/frontend/src/sagas/utils.js
new file mode 100644
index 00000000..28017c87
--- /dev/null
+++ b/frontend/src/sagas/utils.js
@@ -0,0 +1,10 @@
+import { SevenWondersSession } from '../api/sevenWondersApi';
+import { eventChannel } from 'redux-saga';
+
+type Emitter = (value: any) => void;
+
+export function createChannel(session: SevenWondersSession, methodWithCallback: () => void, ...args: Array<any>) {
+ return eventChannel((emitter: Emitter) => {
+ return methodWithCallback.call(session, ...args, emitter);
+ });
+}
bgstack15