@laserware/stasis
    Preparing search index...

    Function takeLatest

    • Spawns a saga on each action dispatched to the Store that matches pattern. And automatically cancels any previous saga task started previously if it's still running.

      Each time an action is dispatched to the store. And if this action matches pattern, takeLatest starts a new saga task in the background. If a saga task was started previously (on the last action dispatched before the actual action), and if this task is still running, the task will be cancelled.

      In the following example, we create a basic task fetchUser. We use takeLatest to start a new fetchUser task on each dispatched USER_REQUESTED action. Since takeLatest cancels any pending task started previously, we ensure that if a user triggers multiple consecutive USER_REQUESTED actions rapidly, we'll only conclude with the latest action

      import { takeLatest } from redux-saga/effects

      function* fetchUser(action) { ... }

      function* watchLastFetchUser() { yield takeLatest('USER_REQUESTED', fetchUser) }

      takeLatest is a high-level API built using take and fork. Here is how the helper could be implemented using the low-level Effects

      const takeLatest = (patternOrChannel, saga, ...args) => fork(function*() { let lastTask while (true) { const action = yield take(patternOrChannel) if (lastTask) { yield cancel(lastTask) // cancel is no-op if the task has already terminated } lastTask = yield fork(saga, ...args.concat(action)) } })

      Type Parameters

      • P extends ActionPattern

      Parameters

      • pattern: P

        for more information see docs for take(pattern)

      • worker: (action: ActionMatchingPattern<P>) => any

      Returns ForkEffect<never>

    • Spawns a saga on each action dispatched to the Store that matches pattern. And automatically cancels any previous saga task started previously if it's still running.

      Each time an action is dispatched to the store. And if this action matches pattern, takeLatest starts a new saga task in the background. If a saga task was started previously (on the last action dispatched before the actual action), and if this task is still running, the task will be cancelled.

      In the following example, we create a basic task fetchUser. We use takeLatest to start a new fetchUser task on each dispatched USER_REQUESTED action. Since takeLatest cancels any pending task started previously, we ensure that if a user triggers multiple consecutive USER_REQUESTED actions rapidly, we'll only conclude with the latest action

      import { takeLatest } from redux-saga/effects

      function* fetchUser(action) { ... }

      function* watchLastFetchUser() { yield takeLatest('USER_REQUESTED', fetchUser) }

      takeLatest is a high-level API built using take and fork. Here is how the helper could be implemented using the low-level Effects

      const takeLatest = (patternOrChannel, saga, ...args) => fork(function*() { let lastTask while (true) { const action = yield take(patternOrChannel) if (lastTask) { yield cancel(lastTask) // cancel is no-op if the task has already terminated } lastTask = yield fork(saga, ...args.concat(action)) } })

      Type Parameters

      • P extends ActionPattern
      • Fn extends (...args: any[]) => any

      Parameters

      • pattern: P

        for more information see docs for take(pattern)

      • worker: Fn
      • ...args: HelperWorkerParameters<ActionMatchingPattern<P>, Fn>

        arguments to be passed to the started task. takeLatest will add the incoming action to the argument list (i.e. the action will be the last argument provided to saga)

      Returns ForkEffect<never>

    • Spawns a saga on each action dispatched to the Store that matches pattern. And automatically cancels any previous saga task started previously if it's still running.

      Each time an action is dispatched to the store. And if this action matches pattern, takeLatest starts a new saga task in the background. If a saga task was started previously (on the last action dispatched before the actual action), and if this task is still running, the task will be cancelled.

      In the following example, we create a basic task fetchUser. We use takeLatest to start a new fetchUser task on each dispatched USER_REQUESTED action. Since takeLatest cancels any pending task started previously, we ensure that if a user triggers multiple consecutive USER_REQUESTED actions rapidly, we'll only conclude with the latest action

      import { takeLatest } from redux-saga/effects

      function* fetchUser(action) { ... }

      function* watchLastFetchUser() { yield takeLatest('USER_REQUESTED', fetchUser) }

      takeLatest is a high-level API built using take and fork. Here is how the helper could be implemented using the low-level Effects

      const takeLatest = (patternOrChannel, saga, ...args) => fork(function*() { let lastTask while (true) { const action = yield take(patternOrChannel) if (lastTask) { yield cancel(lastTask) // cancel is no-op if the task has already terminated } lastTask = yield fork(saga, ...args.concat(action)) } })

      Type Parameters

      • A extends Action

      Parameters

      • pattern: ActionPattern<A>

        for more information see docs for take(pattern)

      • worker: (action: A) => any

      Returns ForkEffect<never>

    • Spawns a saga on each action dispatched to the Store that matches pattern. And automatically cancels any previous saga task started previously if it's still running.

      Each time an action is dispatched to the store. And if this action matches pattern, takeLatest starts a new saga task in the background. If a saga task was started previously (on the last action dispatched before the actual action), and if this task is still running, the task will be cancelled.

      In the following example, we create a basic task fetchUser. We use takeLatest to start a new fetchUser task on each dispatched USER_REQUESTED action. Since takeLatest cancels any pending task started previously, we ensure that if a user triggers multiple consecutive USER_REQUESTED actions rapidly, we'll only conclude with the latest action

      import { takeLatest } from redux-saga/effects

      function* fetchUser(action) { ... }

      function* watchLastFetchUser() { yield takeLatest('USER_REQUESTED', fetchUser) }

      takeLatest is a high-level API built using take and fork. Here is how the helper could be implemented using the low-level Effects

      const takeLatest = (patternOrChannel, saga, ...args) => fork(function*() { let lastTask while (true) { const action = yield take(patternOrChannel) if (lastTask) { yield cancel(lastTask) // cancel is no-op if the task has already terminated } lastTask = yield fork(saga, ...args.concat(action)) } })

      Type Parameters

      • A extends Action
      • Fn extends (...args: any[]) => any

      Parameters

      • pattern: ActionPattern<A>

        for more information see docs for take(pattern)

      • worker: Fn
      • ...args: HelperWorkerParameters<A, Fn>

        arguments to be passed to the started task. takeLatest will add the incoming action to the argument list (i.e. the action will be the last argument provided to saga)

      Returns ForkEffect<never>

    • You can also pass in a channel as argument and the behaviour is the same as takeLatest(pattern, saga, ...args).

      Type Parameters

      • T

      Parameters

      • channel: TakeableChannel<T>
      • worker: (item: T) => any

      Returns ForkEffect<never>

    • Spawns a saga on each action dispatched to the Store that matches pattern. And automatically cancels any previous saga task started previously if it's still running.

      Each time an action is dispatched to the store. And if this action matches pattern, takeLatest starts a new saga task in the background. If a saga task was started previously (on the last action dispatched before the actual action), and if this task is still running, the task will be cancelled.

      In the following example, we create a basic task fetchUser. We use takeLatest to start a new fetchUser task on each dispatched USER_REQUESTED action. Since takeLatest cancels any pending task started previously, we ensure that if a user triggers multiple consecutive USER_REQUESTED actions rapidly, we'll only conclude with the latest action

      import { takeLatest } from redux-saga/effects

      function* fetchUser(action) { ... }

      function* watchLastFetchUser() { yield takeLatest('USER_REQUESTED', fetchUser) }

      takeLatest is a high-level API built using take and fork. Here is how the helper could be implemented using the low-level Effects

      const takeLatest = (patternOrChannel, saga, ...args) => fork(function*() { let lastTask while (true) { const action = yield take(patternOrChannel) if (lastTask) { yield cancel(lastTask) // cancel is no-op if the task has already terminated } lastTask = yield fork(saga, ...args.concat(action)) } })

      Type Parameters

      • T
      • Fn extends (...args: any[]) => any

      Parameters

      • channel: TakeableChannel<T>
      • worker: Fn
      • ...args: HelperWorkerParameters<T, Fn>

        arguments to be passed to the started task. takeLatest will add the incoming action to the argument list (i.e. the action will be the last argument provided to saga)

      Returns ForkEffect<never>