本文整理匯總了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,
});
}
示例2: testRace
function* testRace(): SagaIterator {
yield race({
call: call(() => {})
});
// typings:expect-error
yield race({
call: 1
});
// typings:expect-error
yield race({
call: () => {}
});
}
示例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
}
}
示例4: fork
yield fork(function* () {
const { success } = yield race({ success: take(SIGNUP_SUCCESS), otherwise: take(SIGNUP_FAILURE) });
if (success) {
yield call(createToken, { email, password });
}
});
示例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;
}
}
}
示例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)
}
}
示例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()
}
}
}
}
示例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 })
}
}
}
}
示例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])
}
示例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();
}
}