• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript effects.delay函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中redux-saga/effects.delay函数的典型用法代码示例。如果您正苦于以下问题:TypeScript delay函数的具体用法?TypeScript delay怎么用?TypeScript delay使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了delay函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: testDelay

function* testDelay(): SagaIterator {
  // typings:expect-error
  yield delay();
  yield delay(1);
  // typings:expect-error
  yield delay<'result'>(1, 'foo');
  yield delay<'result'>(1, 'result');
  yield delay(1, 'result');
}
开发者ID:javarouka,项目名称:redux-saga,代码行数:9,代码来源:effects.ts


示例2: aiJudgeScore

function * aiJudgeScore () {
  const { board, player, ai, version } = yield select()
  const scores = []
  const judge = judgeScores[version]
  invariant(judge, 'version error')
  const chess = getCandidate(player)
  for (let r = 0; r < 8; r += 1) {
    for (let c = 0; c < 8; c += 1) {
      if (board[r][c] === chess) {
        let score = judge(board, ai, r, c)
        scores.push({
          row: r,
          col: c,
          score: score
        })
      }
    }
  }
  invariant(scores.length, 'Invalid State: Candidates not place')
  const { score } = head(orderBy(scores, 'score', 'desc'))
  const { row, col } = sample(filter(scores, ['score', score])) // A little random
  yield delay(300) // A little delay
  yield put(
    pushLog({
      player,
      pos: `(${row}, ${col})`
    })
  )
  yield call(flipAllChess, { row, col, player })
  yield put(placeChess(row, col, player))
}
开发者ID:DanSnow,项目名称:react-reversi,代码行数:31,代码来源:saga.ts


示例3: authSaga

export function* authSaga(
    history: History,
    authApi: IAuthApi,
    usersApi: IUsersApi
) {
    let token: IToken = yield call(authApi.getAuthToken)

    if (token) {
        token = yield call(login, history, authApi, usersApi, { type: 'token', token })
    } else {
        yield put(actions.logoutSuccess())
    }

    yield put(actions.authCheckFinished(token && token.value || null))

    while (true) {
        if (!token) {
            const { payload: credentials } = yield take(actions.login.getType())
            token = yield call(login, history, authApi, usersApi, credentials)
            if (token) {
                history.push('/')
            }
        }

        if (!token) {
            continue
        }

        let userLoggedOut = false
        while (!userLoggedOut) {
            const { expired } = yield race({
                expired: delay(Math.max(token.exp - Date.now() - 30000, 0)),
                loggedOut: take(actions.logout.getType()),
            })

            if (expired) {
                token = yield call(login, history, authApi, usersApi, { type: 'token', token })
            } else {
                yield call(logout, authApi)
                userLoggedOut = true
            }
        }
    }
}
开发者ID:steam-react,项目名称:steam,代码行数:44,代码来源:auth.ts


示例4: demoAIMasterSaga

export function* demoAIMasterSaga() {
  while (true) {
    const tankId = getNextId('tank')
    const tank = new TankRecord({
      tankId,
      x: 5.5 * B,
      y: 0.5 * B,
      side: 'bot',
      level: 'basic',
      hp: 1,
      direction: 'left',
    })
    yield spawnTank(tank, 1.5)
    yield take((action: Action) => action.type === A.Hit && action.targetTank.tankId === tankId)
    yield put(actions.setTankToDead(tankId))
    yield explosionFromTank(tank)
    yield delay(7e3)
  }
}
开发者ID:socoolxin,项目名称:battle-city,代码行数:19,代码来源:fireDemoSaga.ts


示例5: gameSaga

/**
 *  game-saga负责管理整体游戏进度
 *  负责管理游戏开始界面, 游戏结束界面
 *  game-stage调用stage-saga来运行不同的关卡
 *  并根据stage-saga返回的结果选择继续下一个关卡, 或是选择游戏结束
 */
export default function* gameSaga(action: actions.StartGame | actions.ResetGame) {
  if (action.type === A.ResetGame) {
    DEV.LOG && console.log('GAME RESET')
    return
  }

  // 这里的 delay(0) 是为了「异步执行」后续的代码
  // 以保证后续代码执行前已有的cancel逻辑执行完毕
  yield delay(0)
  DEV.LOG && console.log('GAME STARTED')

  const players = [playerSaga('player-1', PLAYER_CONFIGS.player1)]
  if (yield select(selectors.isInMultiPlayersMode)) {
    players.push(playerSaga('player-2', PLAYER_CONFIGS.player2))
  }

  const result = yield race({
    tick: tickEmitter({ bindESC: true }),
    players: all(players),
    ai: botMasterSaga(),
    powerUp: powerUpManager(),
    bullets: bulletsSaga(),
    // 上面几个 saga 在一个 gameSaga 的生命周期内被认为是后台服务
    // 当 stage-flow 退出(或者是用户直接离开了game-scene)的时候,自动取消上面几个后台服务
    flow: stageFlow(action.stageIndex),
    leave: take(A.LeaveGameScene),
  })

  if (DEV.LOG) {
    if (result.leave) {
      console.log('LEAVE GAME SCENE')
    }
  }

  if (result.flow) {
    DEV.LOG && console.log('GAME ENDED')
    const { router }: State = yield select()
    yield put(replace(`/gameover${router.location.search}`))
  }
  yield put(actions.beforeEndGame())
  yield put(actions.endGame())
}
开发者ID:socoolxin,项目名称:battle-city,代码行数:48,代码来源:gameSaga.ts


示例6: setFireToTrueEvery3Seconds

 function* setFireToTrueEvery3Seconds() {
   while (true) {
     fire = true
     yield delay(3000)
   }
 }
开发者ID:socoolxin,项目名称:battle-city,代码行数:6,代码来源:fireDemoSaga.ts


示例7: select

export const recommendationsSaga = (storeApi: IStoreApi) => function* () {
    // No recommendations until logged in
    const loggedIn = yield select(isLoggedIn)
    if (!loggedIn) {
        yield take(authActions.loginSuccess.getType())
    }

    const token = yield select(getAuthToken)

    // Will initialize this later on first scroll to bottom
    let tagItems: IterableIterator<ITagItems | undefined> | null = null
    let similarItems: IterableIterator<string[] | undefined> | null = null

    // Event channel to watch
    const scrollChannel = yield call(createScrollChannel)

    while (true) {
        // Wait until user scrolls
        const scrollInfo = yield take(scrollChannel)
        if (scrollInfo.pixelsLeft < PIXELS_LEFT_TO_START) {
            yield put(recommendationsActions.setIsLoading(true))

            // Initialize recommendations
            if (!tagItems || !similarItems) {
                const { data: recommendations } = yield call(storeApi.getRecommendations, token)
                tagItems = getTagItems(recommendations.tags)
                similarItems = getSimilarItems(
                    {
                        wishlist: recommendations.wishlist,
                        friends: recommendations.friends,
                        curators: recommendations.curators,
                        played: recommendations.played,
                    },
                    yield select(getIgnoredProducts),
                    yield select(getOwnedProducts),
                )
                tagItems.next()
                similarItems.next()
            }

            // Get next page of recommendations
            const page = yield call(
                getRecommendationsPage,
                tagItems,
                similarItems,
                token,
                storeApi
            )

            // Show 'out of recommendations' message
            if (page === null) {
                yield put(recommendationsActions.setIsFinished(true))
                yield put(recommendationsActions.setIsLoading(false))
                scrollChannel.close()
                break
            }

            // Display recommendations page
            yield put(productActions.add(page.products))
            yield put(recommendationsActions.addPage(page.items))
            yield put(recommendationsActions.setIsLoading(false))
        }

        // Throttle
        yield delay(100)
    }
}
开发者ID:steam-react,项目名称:steam,代码行数:67,代码来源:recommendations.ts


示例8: testDelay

function* testDelay(): SagaIterator {
  // typings:expect-error
  yield delay()
  yield delay(1)
}
开发者ID:rahulrcopart,项目名称:redux-saga,代码行数:5,代码来源:effects.ts


示例9: settingsStoredToast

function* settingsStoredToast() {
  yield put(addToast('Settings saved'));
  yield delay(toastLifetime);
  yield put(removeToast());
}
开发者ID:tylerFowler,项目名称:chrome-dashboard,代码行数:5,代码来源:sagas.ts



注:本文中的redux-saga/effects.delay函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript effects.flush函数代码示例发布时间:2022-05-25
下一篇:
TypeScript effects.cps函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap