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)
}
})
length of a time window in milliseconds during which actions will be ignored after the action starts processing
for more information see docs for take(pattern)
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)
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)
}
})
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)
}
})
length of a time window in milliseconds during which actions will be ignored after the action starts processing
for more information see docs for take(pattern)
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)
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)
}
})
length of a time window in milliseconds during which actions will be ignored after the action starts processing
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)
Spawns a
sagaon an action dispatched to the Store that matchespattern. After spawning a task it's still accepting incoming actions into the underlyingbuffer, keeping at most 1 (the most recent one), but in the same time holding up with spawning new task formsmilliseconds (hence its name -throttle). Purpose of this is to ignore incoming actions for a given period of time while processing a task.Example
In the following example, we create a basic task
fetchAutocomplete. We usethrottleto start a newfetchAutocompletetask on dispatchedFETCH_AUTOCOMPLETEaction. However sincethrottleignores consecutiveFETCH_AUTOCOMPLETEfor some time, we ensure that user won't flood our server with requests.import { call, put, throttle } from
redux-saga/effectsfunction* 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) }
Notes
throttleis a high-level API built usingtake,forkandactionChannel. Here is how the helper could be implemented using the low-level Effectsconst throttle = (ms, pattern, task, ...args) => fork(function*() { const throttleChannel = yield actionChannel(pattern, buffers.sliding(1))
})