@laserware/stasis
    Preparing search index...

    Function debounce

    • Spawns a saga on an action dispatched to the Store that matches pattern. Saga will be called after it stops taking pattern actions for ms milliseconds. Purpose of this is to prevent calling saga until the actions are settled off.

      In the following example, we create a basic task fetchAutocomplete. We use debounce to delay calling fetchAutocomplete saga until we stop receive any FETCH_AUTOCOMPLETE events for at least 1000 ms.

      import { call, put, debounce } from redux-saga/effects

      function* fetchAutocomplete(action) { const autocompleteProposals = yield call(Api.fetchAutocomplete, action.text) yield put({type: 'FETCHED_AUTOCOMPLETE_PROPOSALS', proposals: autocompleteProposals}) }

      function* debounceAutocomplete() { yield debounce(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const debounce = (ms, pattern, task, ...args) => fork(function*() { while (true) { let action = yield take(pattern)

         while (true) {
           const { debounced, _action } = yield race({
             debounced: delay(ms),
             _action: take(pattern)
           })
      
           if (debounced) {
             yield fork(worker, ...args, action)
             break
           }
      
           action = _action
         }
       }
      

      })

      Type Parameters

      • P extends ActionPattern

      Parameters

      • ms: number

        defines how many milliseconds should elapse since the last time pattern action was fired to call the saga

      • pattern: P

        for more information see docs for take(pattern)

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

      Returns ForkEffect<never>

    • Spawns a saga on an action dispatched to the Store that matches pattern. Saga will be called after it stops taking pattern actions for ms milliseconds. Purpose of this is to prevent calling saga until the actions are settled off.

      In the following example, we create a basic task fetchAutocomplete. We use debounce to delay calling fetchAutocomplete saga until we stop receive any FETCH_AUTOCOMPLETE events for at least 1000 ms.

      import { call, put, debounce } from redux-saga/effects

      function* fetchAutocomplete(action) { const autocompleteProposals = yield call(Api.fetchAutocomplete, action.text) yield put({type: 'FETCHED_AUTOCOMPLETE_PROPOSALS', proposals: autocompleteProposals}) }

      function* debounceAutocomplete() { yield debounce(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const debounce = (ms, pattern, task, ...args) => fork(function*() { while (true) { let action = yield take(pattern)

         while (true) {
           const { debounced, _action } = yield race({
             debounced: delay(ms),
             _action: take(pattern)
           })
      
           if (debounced) {
             yield fork(worker, ...args, action)
             break
           }
      
           action = _action
         }
       }
      

      })

      Type Parameters

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

      Parameters

      • ms: number

        defines how many milliseconds should elapse since the last time pattern action was fired to call the saga

      • 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. debounce 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 an action dispatched to the Store that matches pattern. Saga will be called after it stops taking pattern actions for ms milliseconds. Purpose of this is to prevent calling saga until the actions are settled off.

      In the following example, we create a basic task fetchAutocomplete. We use debounce to delay calling fetchAutocomplete saga until we stop receive any FETCH_AUTOCOMPLETE events for at least 1000 ms.

      import { call, put, debounce } from redux-saga/effects

      function* fetchAutocomplete(action) { const autocompleteProposals = yield call(Api.fetchAutocomplete, action.text) yield put({type: 'FETCHED_AUTOCOMPLETE_PROPOSALS', proposals: autocompleteProposals}) }

      function* debounceAutocomplete() { yield debounce(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const debounce = (ms, pattern, task, ...args) => fork(function*() { while (true) { let action = yield take(pattern)

         while (true) {
           const { debounced, _action } = yield race({
             debounced: delay(ms),
             _action: take(pattern)
           })
      
           if (debounced) {
             yield fork(worker, ...args, action)
             break
           }
      
           action = _action
         }
       }
      

      })

      Type Parameters

      • A extends Action

      Parameters

      • ms: number

        defines how many milliseconds should elapse since the last time pattern action was fired to call the saga

      • pattern: ActionPattern<A>

        for more information see docs for take(pattern)

      • worker: (action: A) => any

      Returns ForkEffect<never>

    • Spawns a saga on an action dispatched to the Store that matches pattern. Saga will be called after it stops taking pattern actions for ms milliseconds. Purpose of this is to prevent calling saga until the actions are settled off.

      In the following example, we create a basic task fetchAutocomplete. We use debounce to delay calling fetchAutocomplete saga until we stop receive any FETCH_AUTOCOMPLETE events for at least 1000 ms.

      import { call, put, debounce } from redux-saga/effects

      function* fetchAutocomplete(action) { const autocompleteProposals = yield call(Api.fetchAutocomplete, action.text) yield put({type: 'FETCHED_AUTOCOMPLETE_PROPOSALS', proposals: autocompleteProposals}) }

      function* debounceAutocomplete() { yield debounce(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const debounce = (ms, pattern, task, ...args) => fork(function*() { while (true) { let action = yield take(pattern)

         while (true) {
           const { debounced, _action } = yield race({
             debounced: delay(ms),
             _action: take(pattern)
           })
      
           if (debounced) {
             yield fork(worker, ...args, action)
             break
           }
      
           action = _action
         }
       }
      

      })

      Type Parameters

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

      Parameters

      • ms: number

        defines how many milliseconds should elapse since the last time pattern action was fired to call the saga

      • 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. debounce 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 debounce(ms, pattern, saga, ...args).

      Type Parameters

      • T

      Parameters

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

      Returns ForkEffect<never>

    • Spawns a saga on an action dispatched to the Store that matches pattern. Saga will be called after it stops taking pattern actions for ms milliseconds. Purpose of this is to prevent calling saga until the actions are settled off.

      In the following example, we create a basic task fetchAutocomplete. We use debounce to delay calling fetchAutocomplete saga until we stop receive any FETCH_AUTOCOMPLETE events for at least 1000 ms.

      import { call, put, debounce } from redux-saga/effects

      function* fetchAutocomplete(action) { const autocompleteProposals = yield call(Api.fetchAutocomplete, action.text) yield put({type: 'FETCHED_AUTOCOMPLETE_PROPOSALS', proposals: autocompleteProposals}) }

      function* debounceAutocomplete() { yield debounce(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const debounce = (ms, pattern, task, ...args) => fork(function*() { while (true) { let action = yield take(pattern)

         while (true) {
           const { debounced, _action } = yield race({
             debounced: delay(ms),
             _action: take(pattern)
           })
      
           if (debounced) {
             yield fork(worker, ...args, action)
             break
           }
      
           action = _action
         }
       }
      

      })

      Type Parameters

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

      Parameters

      • ms: number

        defines how many milliseconds should elapse since the last time pattern action was fired to call the saga

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

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

      Returns ForkEffect<never>