How to use the @redux-saga/core/effects.select 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 / app / store / sagas / actions / cardShop.ts View on Github external
function*(action) {
            const state: AppState = yield select();

            const gamePhase = state.game.phase;

            // not in correct phase
            if (gamePhase === GamePhase.WAITING || gamePhase === GamePhase.DEAD) {
                return;
            }

            const card = state.cards[action.payload.index];
            const money = state.game.money;

            // card doesn't exist or player can't afford
            if (!card || money < card.cost) {
                return;
            }
github Jameskmonger / creature-chess / src / app / store / sagas / actions / networking.ts View on Github external
function*() {
                const state: AppState = yield select();

                // if player not connected yet, don't try to reconnect
                if (state.localPlayer.id === null) {
                    yield put(updateConnectionStatus(ConnectionStatus.DISCONNECTED_FINAL));
                    return;
                }

                const packet: ReconnectAuthenticatePacket = {
                    gameId: state.game.gameId,
                    playerId: state.localPlayer.id,
                    reconnectSecret: state.localPlayer.reconnectionSecret
                };
            
                yield put(sendPacket(ClientToServerPacketOpcodes.RECONNECT_AUTHENTICATE, packet));
            }
        )
github ETCDEVTeam / emerald-wallet / packages / store / src / accounts / sagas.ts View on Github external
function* fetchErc20Balances (api: IApi, action: IFetchErc20BalancesAction): SagaIterator {
  const accounts: AddressMap[] = yield select(allAsArray);
  for (const acc of accounts) {
    const address = acc.get('id');
    const chain = acc.get('blockchain').toLowerCase();

    // Look up all known tokens for current blockchain
    const _tokens = registry.all()[chain as BlockchainCode];

    // Request balance for each token for current address
    for (const t of _tokens) {
      yield put(requestTokenBalance(chain, t, address));
    }
  }
}
github Jameskmonger / creature-chess / src / app / sagas / actions / processBattle.ts View on Github external
function*(action) {
            if (isGamePhaseUpdate(GamePhase.PREPARING, action) || isGamePhaseUpdate(GamePhase.READY, action)) {
                // don't do anything, just cancel the old one
                const pieces = (action.payload as any).payload.pieces;

                yield put(BoardActions.piecesUpdated(pieces));
                return;
            }

            const state: AppState = yield select();

            const battleChannel = yield call(startBattle, turnSimulator, state.board, Constants.TURNS_IN_BATTLE);

            yield takeEvery(battleChannel, function*(battleAction: BattleAction) {
                switch (battleAction.type) {
                    case BATTLE_TURN:
                        yield put(BoardActions.piecesUpdated(battleAction.payload.pieces));
                    case BATTLE_FINISHED:
                        yield put(battleAction);
                    default:
                        return;
                }
            });
        }
    );
github ETCDEVTeam / emerald-wallet / packages / store / src / accounts / sagas.ts View on Github external
function* fetchHdPaths (api: IApi, action: IFetchHdPathsAction) {
  const accounts: AddressList = yield select(all);
  const hwAccounts: AddressMap[] = accounts.filter((a: any) => a.get('hardware', true)).toArray();
  for (const item of hwAccounts) {
    const address = item.get('id');
    const chain = item.get('blockchain').toLowerCase();
    const result = yield call(api.emerald.exportAccount, address, chain);

    yield put({
      type: ActionTypes.SET_HD_PATH,
      accountId: address,
      hdpath: result.crypto.hd_path,
      blockchain: chain
    });
  }
}