How to use the @redux-saga/core/effects.takeLatest 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
return function*() {
        const sagaState = {
            evolutionLocked: false
        };

        yield all([
            yield takeLatest(
                [ LOCK_EVOLUTIONS, UNLOCK_EVOLUTIONS ],
                function*(action) {
                    sagaState.evolutionLocked = (action.type === LOCK_EVOLUTIONS);
                }
            ),
            yield takeLatest(
                BenchActionTypes.BENCH_PIECE_ADDED,
                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];
github Jameskmonger / creature-chess / src / shared / board / sagas / evolution.ts View on Github external
return function*() {
        const sagaState = {
            evolutionLocked: false
        };

        yield all([
            yield takeLatest(
                [ LOCK_EVOLUTIONS, UNLOCK_EVOLUTIONS ],
                function*(action) {
                    sagaState.evolutionLocked = (action.type === LOCK_EVOLUTIONS);
                }
            ),
            yield takeLatest(
                BenchActionTypes.BENCH_PIECE_ADDED,
                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);
                    }
github ETCDEVTeam / emerald-wallet / packages / store / src / accounts / sagas.ts View on Github external
export function* root (api: IApi) {
  yield takeLatest(ActionTypes.FETCH_HD_PATHS, fetchHdPaths, api);
  yield takeLatest(ActionTypes.FETCH_ERC20_BALANCES, fetchErc20Balances, api);
}
github ETCDEVTeam / emerald-wallet / packages / store / src / accounts / sagas.ts View on Github external
export function* root (api: IApi) {
  yield takeLatest(ActionTypes.FETCH_HD_PATHS, fetchHdPaths, api);
  yield takeLatest(ActionTypes.FETCH_ERC20_BALANCES, fetchErc20Balances, api);
}
github Jameskmonger / creature-chess / src / app / sagas / actions / notifications.ts View on Github external
const clearNotifications = function*() {
    yield takeLatest(BANNER_UPDATED, function*() {
        yield delay(1000);

        yield put(bannerUpdatedAction(null));
    });
};
github Jameskmonger / creature-chess / src / app / sagas / actions / notifications.ts View on Github external
const sendNotifications = function*() {
    yield takeLatest(GAME_STATE_UPDATE, function*(action) {
        const stateLength = Constants.STATE_LENGTHS[action.payload.phase];

        if (stateLength) {
            yield put(bannerUpdatedAction(`${GameState[action.payload.phase]}, ${stateLength} seconds`));
        }

        const channel = yield call(countdown, stateLength);
        yield takeEvery(channel, function*(secs) {
            yield put(bannerUpdatedAction(`${GameState[action.payload.phase]}, ${secs} seconds`));
        });
    });
};
github Jameskmonger / creature-chess / src / app / store / sagas / actions / phaseTimer.ts View on Github external
export const phaseTimer = function*() {
    yield takeLatest(GAME_PHASE_UPDATE, function*(action) {
        const phaseLength = Constants.PHASE_LENGTHS[action.payload.phase];

        if (phaseLength) {
            yield put(phaseTimerUpdated(phaseLength));

            const channel = yield call(countdown, phaseLength);

            yield takeEvery(channel, function*(secs: number) {
                yield put(phaseTimerUpdated(secs));
            });
        }
    });
};