@laserware/stasis
    Preparing search index...

    Function throttle

    • Spawns a saga on an action dispatched to the Store that matches pattern. After spawning a task it's still accepting incoming actions into the underlying buffer, keeping at most 1 (the most recent one), but in the same time holding up with spawning new task for ms milliseconds (hence its name - throttle). Purpose of this is to ignore incoming actions for a given period of time while processing a task.

      In the following example, we create a basic task fetchAutocomplete. We use throttle to start a new fetchAutocomplete task on dispatched FETCH_AUTOCOMPLETE action. However since throttle ignores consecutive FETCH_AUTOCOMPLETE for some time, we ensure that user won't flood our server with requests.

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

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

      function* throttleAutocomplete() { yield throttle(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const throttle = (ms, pattern, task, ...args) => fork(function*() { const throttleChannel = yield actionChannel(pattern, buffers.sliding(1))

       while (true) {
         const action = yield take(throttleChannel)
         yield fork(task, ...args, action)
         yield delay(ms)
       }
      

      })

      Type Parameters

      • P extends ActionPattern

      Parameters

      • ms: number

        length of a time window in milliseconds during which actions will be ignored after the action starts processing

      • 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. After spawning a task it's still accepting incoming actions into the underlying buffer, keeping at most 1 (the most recent one), but in the same time holding up with spawning new task for ms milliseconds (hence its name - throttle). Purpose of this is to ignore incoming actions for a given period of time while processing a task.

      In the following example, we create a basic task fetchAutocomplete. We use throttle to start a new fetchAutocomplete task on dispatched FETCH_AUTOCOMPLETE action. However since throttle ignores consecutive FETCH_AUTOCOMPLETE for some time, we ensure that user won't flood our server with requests.

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

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

      function* throttleAutocomplete() { yield throttle(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const throttle = (ms, pattern, task, ...args) => fork(function*() { const throttleChannel = yield actionChannel(pattern, buffers.sliding(1))

       while (true) {
         const action = yield take(throttleChannel)
         yield fork(task, ...args, action)
         yield delay(ms)
       }
      

      })

      Type Parameters

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

      Parameters

      • ms: number

        length of a time window in milliseconds during which actions will be ignored after the action starts processing

      • 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. throttle 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. After spawning a task it's still accepting incoming actions into the underlying buffer, keeping at most 1 (the most recent one), but in the same time holding up with spawning new task for ms milliseconds (hence its name - throttle). Purpose of this is to ignore incoming actions for a given period of time while processing a task.

      In the following example, we create a basic task fetchAutocomplete. We use throttle to start a new fetchAutocomplete task on dispatched FETCH_AUTOCOMPLETE action. However since throttle ignores consecutive FETCH_AUTOCOMPLETE for some time, we ensure that user won't flood our server with requests.

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

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

      function* throttleAutocomplete() { yield throttle(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const throttle = (ms, pattern, task, ...args) => fork(function*() { const throttleChannel = yield actionChannel(pattern, buffers.sliding(1))

       while (true) {
         const action = yield take(throttleChannel)
         yield fork(task, ...args, action)
         yield delay(ms)
       }
      

      })

      Type Parameters

      • A extends Action

      Parameters

      • ms: number

        length of a time window in milliseconds during which actions will be ignored after the action starts processing

      • 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. After spawning a task it's still accepting incoming actions into the underlying buffer, keeping at most 1 (the most recent one), but in the same time holding up with spawning new task for ms milliseconds (hence its name - throttle). Purpose of this is to ignore incoming actions for a given period of time while processing a task.

      In the following example, we create a basic task fetchAutocomplete. We use throttle to start a new fetchAutocomplete task on dispatched FETCH_AUTOCOMPLETE action. However since throttle ignores consecutive FETCH_AUTOCOMPLETE for some time, we ensure that user won't flood our server with requests.

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

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

      function* throttleAutocomplete() { yield throttle(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const throttle = (ms, pattern, task, ...args) => fork(function*() { const throttleChannel = yield actionChannel(pattern, buffers.sliding(1))

       while (true) {
         const action = yield take(throttleChannel)
         yield fork(task, ...args, action)
         yield delay(ms)
       }
      

      })

      Type Parameters

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

      Parameters

      • ms: number

        length of a time window in milliseconds during which actions will be ignored after the action starts processing

      • 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. throttle 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 throttle(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. After spawning a task it's still accepting incoming actions into the underlying buffer, keeping at most 1 (the most recent one), but in the same time holding up with spawning new task for ms milliseconds (hence its name - throttle). Purpose of this is to ignore incoming actions for a given period of time while processing a task.

      In the following example, we create a basic task fetchAutocomplete. We use throttle to start a new fetchAutocomplete task on dispatched FETCH_AUTOCOMPLETE action. However since throttle ignores consecutive FETCH_AUTOCOMPLETE for some time, we ensure that user won't flood our server with requests.

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

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

      function* throttleAutocomplete() { yield throttle(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete) }

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

      const throttle = (ms, pattern, task, ...args) => fork(function*() { const throttleChannel = yield actionChannel(pattern, buffers.sliding(1))

       while (true) {
         const action = yield take(throttleChannel)
         yield fork(task, ...args, action)
         yield delay(ms)
       }
      

      })

      Type Parameters

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

      Parameters

      • ms: number

        length of a time window in milliseconds during which actions will be ignored after the action starts processing

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

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

      Returns ForkEffect<never>