當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript effects.race函數代碼示例

本文整理匯總了TypeScript中redux-saga/effects.race函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript race函數的具體用法?TypeScript race怎麽用?TypeScript race使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了race函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: testRace

function* testRace(): SagaIterator {
  yield race({
    call: call(() => {})
  });

  // typings:expect-error
  yield race({
    named: 1,
  });

  // typings:expect-error
  yield race({
    named: () => {},
  });

  // typings:expect-error
  yield race({
    named: promise,
  });

  // typings:expect-error
  yield race({
    named1: 1,
    named2: () => {},
    named3: promise,
  });
}
開發者ID:javarouka,項目名稱:redux-saga,代碼行數:27,代碼來源:effects.ts

示例2: testRace

function* testRace(): SagaIterator {
  yield race({
    call: call(() => {})
  });

  // typings:expect-error
  yield race({
    call: 1
  });

  // typings:expect-error
  yield race({
    call: () => {}
  });
}
開發者ID:gajus,項目名稱:redux-saga,代碼行數:15,代碼來源:effects.ts

示例3: login

function* login(history: History, authApi: IAuthApi, usersApi: IUsersApi, credentials: TCredentials) {
    try {
        const { token }: { token: IToken } = yield race({
            token: call(authApi.login, credentials),
            logout: take(actions.logout.getType()),
        })

        if (token) {
            yield call(authApi.setAuthToken, token)
            const user = yield call(usersApi.getTokenOwner, token.value)
            yield put(actions.loginSuccess({
                token: token.value,
                login: user.login,
                userId: user.id,
                avatarUrl: user.avatarUrl,
                displayName: user.displayName
            }))
            return token
        } else {
            yield call(logout, authApi)
        }
    } catch (e) {
        yield call(authApi.removeAuthToken)
        yield put(actions.loginFailure(e))
        return null
    }
}
開發者ID:steam-react,項目名稱:steam,代碼行數:27,代碼來源:auth.ts

示例4: fork

  yield fork(function* () {
    const { success } = yield race({ success: take(SIGNUP_SUCCESS), otherwise: take(SIGNUP_FAILURE) });

    if (success) {
      yield call(createToken, { email, password });
    }
  });
開發者ID:rosendi,項目名稱:figure,代碼行數:7,代碼來源:auth.ts

示例5: authFlow

export function* authFlow() {
  yield fork(watchStorage);
  yield fork(redirectOnAuth);

  while (true) {
    const token = auth.retrieveToken();

    if (token) {
      const state = yield select(state => state.auth);

      if (!state || state.token.toString() !== token.toString()) {
        yield put(signinSuccess(token, false));
      }

      yield call(watchExpiration, token.expiresIn);
    } else {
      yield call(purgeToken, false);
    }

    const { signin, signup } = yield race({ signin: take(SIGNIN), signup: take(SIGNUP), overwise: take(SIGNIN_SUCCESS) });

    if (signin) {
      yield fork(submitSigninForm, signin.resolve, signin.reject);
      yield call(createToken, signin);
      continue;
    }

    if (signup) {
      yield fork(submitSignupForm, signup.resolve, signup.reject);
      yield call(createUser, signup);
      continue;
    }
  }
}
開發者ID:rosendi,項目名稱:figure,代碼行數:34,代碼來源:auth.ts

示例6: watchCreateAndRemoveLastPosition

// use channel to make sure every create/remove run one by one
function* watchCreateAndRemoveLastPosition(): SagaIterator {
  try {
    const createLastPositionChan: TakeableChannel<{}> = yield actionChannel(
      getType(lastPositionsCreator.createLastPosition)
    )
    const removeLastPositionChan: TakeableChannel<{}> = yield actionChannel(
      getType(lastPositionsCreator.removeLastPosition)
    )
    while (true) {
      const [createLastPositionAction, removeLastPositionAction]: [
        ReturnType<typeof lastPositionsCreator.createLastPosition> | void,
        ReturnType<typeof lastPositionsCreator.removeLastPosition> | void
      ] = yield race([take(createLastPositionChan), take(removeLastPositionChan)])

      if (createLastPositionAction) {
        yield call(createLastPosition, createLastPositionAction)
      }

      if (removeLastPositionAction) {
        yield call(removeLastPosition, removeLastPositionAction)
      }
    }
  } catch (err) {
    console.error(err)
  }
}
開發者ID:foray1010,項目名稱:Popup-my-Bookmarks,代碼行數:27,代碼來源:saga.ts

示例7: simpleFireLoop

export default function* simpleFireLoop(ctx: Bot) {
  let skipDelayAtFirstTime = true
  while (true) {
    if (skipDelayAtFirstTime) {
      skipDelayAtFirstTime = false
    } else {
      const tank: TankRecord = yield select(selectors.tank, ctx.tankId)
      yield race({
        timeout: Timing.delay(tank ? values.bulletInterval(tank) : SIMPLE_FIRE_LOOP_INTERVAL),
        bulletComplete: take(ctx.noteChannel, 'bullet-complete'),
      })
    }

    const tank: TankRecord = yield select(selectors.tank, ctx.tankId)
    if (tank == null) {
      continue
    }
    const fireInfo: TankFireInfo = yield select(selectors.fireInfo, ctx.tankId)
    if (fireInfo.canFire) {
      const { map, tanks }: State = yield select()

      const env = getEnv(map, tanks, tank)
      if (determineFire(tank, env)) {
        ctx.fire()
      }
    }
  }
}
開發者ID:socoolxin,項目名稱:battle-city,代碼行數:28,代碼來源:simpleFireLoop.ts

示例8: botSaga

export default function* botSaga(tankId: TankId) {
  const ctx = new Bot(tankId)
  try {
    yield takeEvery(hitPredicate, hitHandler)
    const result = yield race({
      service: all([
        generateBulletCompleteNote(),
        directionController(tankId, ctx.directionControllerCallback),
        fireController(tankId, ctx.fireControllerCallback),
        AIWorkerSaga(ctx),
      ]),
      killed: take(killedPredicate),
      endGame: take(A.EndGame),
    })
    const tank: TankRecord = yield select(selectors.tank, tankId)
    yield put(actions.setTankToDead(tankId))
    if (result.killed) {
      yield explosionFromTank(tank)
      if (result.killed.method === 'bullet') {
        yield scoreFromKillTank(tank)
      }
    }
    yield put(actions.reqAddBot())
  } finally {
    const tank: TankRecord = yield select(selectors.tank, tankId)
    if (tank && tank.alive) {
      yield put(actions.setTankToDead(tankId))
    }
  }

  function hitPredicate(action: actions.Action) {
    return action.type === actions.A.Hit && action.targetTank.tankId === tankId
  }

  function* hitHandler(action: actions.Hit) {
    const tank: TankRecord = yield select(selectors.tank, tankId)
    DEV.ASSERT && console.assert(tank != null)
    if (tank.hp > 1) {
      yield put(actions.hurt(tank))
    } else {
      const { sourceTank, targetTank } = action
      yield put(actions.kill(targetTank, sourceTank, 'bullet'))
    }
  }

  function killedPredicate(action: actions.Action) {
    return action.type === actions.A.Kill && action.targetTank.tankId === tankId
  }

  function* generateBulletCompleteNote() {
    while (true) {
      const { bulletId }: actions.BeforeRemoveBullet = yield take(actions.A.BeforeRemoveBullet)
      const { bullets }: State = yield select()
      const bullet = bullets.get(bulletId)
      if (bullet.tankId === tankId) {
        ctx.noteChannel.put({ type: 'bullet-complete', bullet })
      }
    }
  }
}
開發者ID:socoolxin,項目名稱:battle-city,代碼行數:60,代碼來源:BotSaga.ts

示例9: testRace

function* testRace(): SagaIterator {
  yield race({
    call: call(() => {}),
  })

  // typings:expect-error
  yield race({
    named: 1,
  })

  // typings:expect-error
  yield race({
    named: () => {},
  })

  // typings:expect-error
  yield race({
    named: promise,
  })

  // typings:expect-error
  yield race({
    named1: 1,
    named2: () => {},
    named3: promise,
  })

  const effectArray = [call(() => {}), call(() => {})]
  yield race([...effectArray])
  // typings:expect-error
  yield race([...effectArray, promise])
}
開發者ID:rahulrcopart,項目名稱:redux-saga,代碼行數:32,代碼來源:effects.ts

示例10: submitSigninForm

function* submitSigninForm(resolve, reject) {
  const { failure } = yield race({ success: take(SIGNIN_SUCCESS), failure: take(SIGNIN_FAILURE)});

  if (failure) {
    typeof failure.reason.message === 'object' ? reject(failure.reason.message) : reject({ _error: failure.reason.message });
  } else {
    resolve();
  }
}
開發者ID:rosendi,項目名稱:figure,代碼行數:9,代碼來源:auth.ts


注:本文中的redux-saga/effects.race函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。