带有 throttle(redux-saga) 的定时器什么时候开始?
When does the timer with throttle(redux-saga) start?
我理解了在 redux-saga 中使用 throttle 的概念。
但我有一个快速的问题,给出的计时器,他什么时候开始?
示例 =>
throttle(500, 'INPUT_CHANGED', handleInput)
As soon as, the method gaven in second parameter start,
and not taking care about the completion of the method ?
.
Or as soon as, the method gaven in second parameter is finish ?
我还没有用过throttle
,但是我的理解是这样的:
您应该在使用 takeLatest
或 takeEvery
的相同位置使用 throttle
。
例如:
// saga.js
function* handleInput(action) {
// This code will not be called more than once every 500ms
}
function* handleSomething(action) {
// This code will be called on every 'SOMETHING_CHANGED' action
}
export default function* rootSaga() {
yield all([
takeEvery('SOMETHING_CHANGED', handleSomething),
throttle(500, 'INPUT_CHANGED', handleInput),
])
}
// store.js
const sagaMiddleware = createSagaMiddleware()
sagaMiddleware.run(rootSaga)
希望对您有所帮助。
throttle => 关于第一个参数:
ms: 数字 - 时间长度window 以毫秒为单位,在此期间操作将被忽略在操作开始处理后
我相信是的,计时器在调用操作后立即开始,我们不关心此任务的完成情况。
(最好阅读文档,我的错)
我理解了在 redux-saga 中使用 throttle 的概念。 但我有一个快速的问题,给出的计时器,他什么时候开始? 示例 =>
throttle(500, 'INPUT_CHANGED', handleInput)
As soon as, the method gaven in second parameter start,
and not taking care about the completion of the method ?
.
Or as soon as, the method gaven in second parameter is finish ?
我还没有用过throttle
,但是我的理解是这样的:
您应该在使用 takeLatest
或 takeEvery
的相同位置使用 throttle
。
例如:
// saga.js
function* handleInput(action) {
// This code will not be called more than once every 500ms
}
function* handleSomething(action) {
// This code will be called on every 'SOMETHING_CHANGED' action
}
export default function* rootSaga() {
yield all([
takeEvery('SOMETHING_CHANGED', handleSomething),
throttle(500, 'INPUT_CHANGED', handleInput),
])
}
// store.js
const sagaMiddleware = createSagaMiddleware()
sagaMiddleware.run(rootSaga)
希望对您有所帮助。
throttle => 关于第一个参数:
ms: 数字 - 时间长度window 以毫秒为单位,在此期间操作将被忽略在操作开始处理后
我相信是的,计时器在调用操作后立即开始,我们不关心此任务的完成情况。 (最好阅读文档,我的错)