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


TypeScript effects.delay函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。