Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function*(action) {
const piece = action.payload.piece;
// if evolution is locked, wait for it to be unlocked
if (sagaState.evolutionLocked) {
yield take(UNLOCK_EVOLUTIONS);
yield delay(500);
}
const { bench, board }: TState = yield select(s => ({ bench: s.bench, board: s.board }));
const { stages } = definitionProvider.get(piece.definitionId);
const nextStageIndex = piece.stage + 1;
const nextStage = stages[nextStageIndex];
if (!nextStage) {
return;
}
const pieceIsMatching = (p: Piece) => p.definitionId === piece.definitionId && p.stage === piece.stage;
const getMatchingPieces = (pieces: Piece[]) => pieces.filter(p => p.id !== piece.id && pieceIsMatching(p));
export const preventAccidentalClose = function*() {
yield take(JOIN_COMPLETE);
// display an "Are you sure you want to leave this page?" dialog
window.onbeforeunload = () => "Are you sure you want to leave this page? There is currently no way to rejoin a game";
};
export const networking = function*() {
let action: (FindGameAction | JoinGameAction | CreateGameAction)
= yield take([FIND_GAME, JOIN_GAME, CREATE_GAME]);
const socket: Socket = yield call(getSocket, action.payload.serverIP);
yield put(updateConnectionStatus(ConnectionStatus.CONNECTED));
yield fork(readPacketsToActions, socket);
while (true) {
const { error, response }: JoinLobbyResponse = yield getResponseForAction(socket, action);
if (!error) {
yield put(joinLobbyAction(
response.playerId,
response.lobbyId,
response.players,
response.startTimestamp,
response.isHost