本文整理汇总了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;未经允许,请勿转载。 |
请发表评论