How to use the @redux-saga/core/effects.take function in @redux-saga/core

To help you get started, we’ve selected a few @redux-saga/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jameskmonger / creature-chess / src / shared / board / sagas / evolution.ts View on Github external
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));
github Jameskmonger / creature-chess / src / app / store / sagas / actions / preventAccidentalClose.ts View on Github external
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";
};
github Jameskmonger / creature-chess / src / app / store / sagas / actions / networking.ts View on Github external
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