summaryrefslogtreecommitdiff
path: root/frontend/src/sagas.js
blob: a1f80c73b83cec66d8bb03d34e3b894f72bd4e26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// @flow
import type { History } from 'react-router';
import { router } from 'redux-saga-router';
import { call, fork } from 'redux-saga/effects';
import { connectToGame, SevenWondersSession } from './api/sevenWondersApi';
import { makeSagaRoutes } from './routes';
import errorHandlingSaga from './sagas/errors';

export default function* rootSaga(history: History): * {
  let sevenWondersSession: SevenWondersSession | void;
  try {
    sevenWondersSession = yield call(connectToGame);
  } catch (error) {
    console.error('Could not connect to socket', error);
    return;
  }
  yield fork(errorHandlingSaga, sevenWondersSession);
  yield* router(history, makeSagaRoutes(sevenWondersSession));
}
bgstack15