diff options
author | jbion <joffrey.bion@amadeus.com> | 2019-05-05 11:22:58 +0200 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2019-05-06 18:33:14 +0200 |
commit | 347877687301ec43367105a7f8c49fe16129fc00 (patch) | |
tree | 4999cf1978527658f70a21ce59d5f5d08a7169fd /frontend | |
parent | Convert reducers to typescript (diff) | |
download | seven-wonders-347877687301ec43367105a7f8c49fe16129fc00.tar.gz seven-wonders-347877687301ec43367105a7f8c49fe16129fc00.tar.bz2 seven-wonders-347877687301ec43367105a7f8c49fe16129fc00.zip |
Convert redux sagas to TypeScript
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/src/sagas.ts (renamed from frontend/src/sagas.js) | 5 | ||||
-rw-r--r-- | frontend/src/sagas/errors.ts (renamed from frontend/src/sagas/errors.js) | 18 | ||||
-rw-r--r-- | frontend/src/sagas/game.ts (renamed from frontend/src/sagas/game.js) | 10 | ||||
-rw-r--r-- | frontend/src/sagas/gameBrowser.ts (renamed from frontend/src/sagas/gameBrowser.js) | 12 | ||||
-rw-r--r-- | frontend/src/sagas/home.ts (renamed from frontend/src/sagas/home.js) | 10 | ||||
-rw-r--r-- | frontend/src/sagas/lobby.ts (renamed from frontend/src/sagas/lobby.js) | 12 |
6 files changed, 29 insertions, 38 deletions
diff --git a/frontend/src/sagas.js b/frontend/src/sagas.ts index 1aa72215..03c71b63 100644 --- a/frontend/src/sagas.js +++ b/frontend/src/sagas.ts @@ -1,5 +1,4 @@ -// @flow -import type { SagaIterator } from 'redux-saga'; +import { SagaIterator } from 'redux-saga'; import { call, fork } from 'redux-saga/effects'; import { connectToGame, SevenWondersSession } from './api/sevenWondersApi'; import { errorHandlingSaga } from './sagas/errors'; @@ -9,7 +8,7 @@ import { homeSaga } from './sagas/home'; import { lobbySaga } from './sagas/lobby'; export function* rootSaga(): SagaIterator { - let sevenWondersSession: SevenWondersSession | void; + let sevenWondersSession: SevenWondersSession; try { sevenWondersSession = yield call(connectToGame); } catch (error) { diff --git a/frontend/src/sagas/errors.js b/frontend/src/sagas/errors.ts index 15287645..b27dfa95 100644 --- a/frontend/src/sagas/errors.js +++ b/frontend/src/sagas/errors.ts @@ -1,15 +1,13 @@ -// @flow -import { Toaster } from '@blueprintjs/core'; -import type { Channel, SagaIterator } from 'redux-saga'; -import { eventChannel } from 'redux-saga'; -import { apply, cancelled, take } from 'redux-saga/effects'; -import type { ApiError } from '../api/model'; -import type { SevenWondersSession } from '../api/sevenWondersApi'; +import {Toaster} from '@blueprintjs/core'; +import {Channel, eventChannel} from 'redux-saga'; +import {apply, cancelled, take} from 'redux-saga/effects'; +import {ApiError} from '../api/model'; +import {SevenWondersSession} from '../api/sevenWondersApi'; const ErrorToaster = Toaster.create(); -export function* errorHandlingSaga(session: SevenWondersSession): SagaIterator { - const errorChannel: Channel = yield eventChannel(session.watchErrors()); +export function* errorHandlingSaga(session: SevenWondersSession): any { + const errorChannel: Channel<ApiError> = yield eventChannel(session.watchErrors()); try { while (true) { const error: ApiError = yield take(errorChannel); @@ -23,7 +21,7 @@ export function* errorHandlingSaga(session: SevenWondersSession): SagaIterator { } } -function* handleOneError(err: ApiError): * { +function* handleOneError(err: ApiError): any { console.error('Error received on web socket channel', err); const msg = buildMsg(err); yield apply(ErrorToaster, ErrorToaster.show, [{ intent: 'danger', icon: 'error', message: msg }]); diff --git a/frontend/src/sagas/game.js b/frontend/src/sagas/game.ts index 661c277b..a60ab2d3 100644 --- a/frontend/src/sagas/game.js +++ b/frontend/src/sagas/game.ts @@ -1,6 +1,6 @@ -import { eventChannel } from 'redux-saga'; +import { eventChannel, SagaIterator } from 'redux-saga'; import { apply, call, put, take } from 'redux-saga/effects'; -import type { ApiPlayerTurnInfo, ApiPreparedCard, ApiTable } from '../api/model'; +import { ApiPlayerTurnInfo, ApiPreparedCard, ApiTable } from '../api/model'; import { SevenWondersSession } from '../api/sevenWondersApi'; import { actions, REQUEST_PREPARE_MOVE, REQUEST_SAY_READY } from '../redux/actions/game'; import { ENTER_GAME } from '../redux/actions/lobby'; @@ -41,14 +41,14 @@ function* watchPreparedCards(session: SevenWondersSession, gameId: number) { } } -function* sayReady(session: SevenWondersSession) { +function* sayReady(session: SevenWondersSession): SagaIterator { while (true) { yield take(REQUEST_SAY_READY); yield apply(session, session.sayReady); } } -function* prepareMove(session: SevenWondersSession) { +function* prepareMove(session: SevenWondersSession): SagaIterator { while (true) { let action = yield take(REQUEST_PREPARE_MOVE); yield apply(session, session.prepareMove, [action.move]); @@ -67,7 +67,7 @@ function* watchTurnInfo(session: SevenWondersSession) { } } -export function* gameSaga(session: SevenWondersSession) { +export function* gameSaga(session: SevenWondersSession): SagaIterator { const { gameId } = yield take(ENTER_GAME); console.log('Entered game!', gameId); yield [ diff --git a/frontend/src/sagas/gameBrowser.js b/frontend/src/sagas/gameBrowser.ts index 6b545933..868ec471 100644 --- a/frontend/src/sagas/gameBrowser.js +++ b/frontend/src/sagas/gameBrowser.ts @@ -1,13 +1,11 @@ -// @flow import { push } from 'react-router-redux'; -import type { SagaIterator } from 'redux-saga'; -import { eventChannel } from 'redux-saga'; +import { eventChannel, SagaIterator } from 'redux-saga'; import { all, apply, call, put, take } from 'redux-saga/effects'; -import type { ApiLobby } from '../api/model'; -import type { SevenWondersSession } from '../api/sevenWondersApi'; +import { ApiLobby } from '../api/model'; +import { SevenWondersSession } from '../api/sevenWondersApi'; import { actions as gameActions, REQUEST_CREATE_GAME, REQUEST_JOIN_GAME } from '../redux/actions/lobby'; -function* watchGames(session: SevenWondersSession): SagaIterator { +function* watchGames(session: SevenWondersSession): any { const gamesChannel = yield eventChannel(session.watchGames()); try { while (true) { @@ -19,7 +17,7 @@ function* watchGames(session: SevenWondersSession): SagaIterator { } } -function* watchLobbyJoined(session: SevenWondersSession): SagaIterator { +function* watchLobbyJoined(session: SevenWondersSession): any { const joinedLobbyChannel = yield eventChannel(session.watchLobbyJoined()); try { const joinedLobby: ApiLobby = yield take(joinedLobbyChannel); diff --git a/frontend/src/sagas/home.js b/frontend/src/sagas/home.ts index 237ca004..585c536e 100644 --- a/frontend/src/sagas/home.js +++ b/frontend/src/sagas/home.ts @@ -1,10 +1,8 @@ -// @flow import { push } from 'react-router-redux'; -import type { SagaIterator } from 'redux-saga'; -import { eventChannel } from 'redux-saga'; +import { eventChannel, SagaIterator } from 'redux-saga'; import { all, apply, call, put, take } from 'redux-saga/effects'; -import type { ApiPlayer } from '../api/model'; -import type { SevenWondersSession } from '../api/sevenWondersApi'; +import { ApiPlayer } from '../api/model'; +import { SevenWondersSession } from '../api/sevenWondersApi'; import { actions, REQUEST_CHOOSE_USERNAME } from '../redux/actions/user'; function* sendUsername(session: SevenWondersSession): SagaIterator { @@ -15,7 +13,7 @@ function* sendUsername(session: SevenWondersSession): SagaIterator { } } -function* validateUsername(session: SevenWondersSession): SagaIterator { +function* validateUsername(session: SevenWondersSession): any { const usernameChannel = yield eventChannel(session.watchNameChoice()); while (true) { const user: ApiPlayer = yield take(usernameChannel); diff --git a/frontend/src/sagas/lobby.js b/frontend/src/sagas/lobby.ts index ce840947..09360b02 100644 --- a/frontend/src/sagas/lobby.js +++ b/frontend/src/sagas/lobby.ts @@ -1,13 +1,11 @@ -// @flow import { push } from 'react-router-redux'; -import type { Channel, SagaIterator } from 'redux-saga'; -import { eventChannel } from 'redux-saga'; +import { Channel, eventChannel, SagaIterator } from 'redux-saga'; import { all, apply, call, put, take } from 'redux-saga/effects'; import { SevenWondersSession } from '../api/sevenWondersApi'; import { actions as gameActions, ENTER_LOBBY, REQUEST_START_GAME } from '../redux/actions/lobby'; -function* watchLobbyUpdates(session: SevenWondersSession, lobbyId: number): SagaIterator { - const lobbyUpdatesChannel: Channel = yield eventChannel(session.watchLobbyUpdated(lobbyId)); +function* watchLobbyUpdates(session: SevenWondersSession, lobbyId: number): any { + const lobbyUpdatesChannel: Channel<Object> = yield eventChannel(session.watchLobbyUpdated(lobbyId)); try { while (true) { const lobby = yield take(lobbyUpdatesChannel); @@ -18,7 +16,7 @@ function* watchLobbyUpdates(session: SevenWondersSession, lobbyId: number): Saga } } -function* watchGameStart(session: SevenWondersSession, lobbyId: number): SagaIterator { +function* watchGameStart(session: SevenWondersSession, lobbyId: number): any { const gameStartedChannel = yield eventChannel(session.watchGameStarted(lobbyId)); try { yield take(gameStartedChannel); @@ -32,7 +30,7 @@ function* watchGameStart(session: SevenWondersSession, lobbyId: number): SagaIte function* startGame(session: SevenWondersSession): SagaIterator { while (true) { yield take(REQUEST_START_GAME); - yield apply(session, session.startGame, []); + yield apply(session, session.startGame); } } |