带油门的计时器(redux-saga)何时启动?

时间:2018-03-19 10:24:18

标签: react-native redux redux-saga throttling

我理解在redux-saga中使用throttle的概念。 但是我有一个快速的问题,计时器是gaven,他什么时候开始? 示例=>

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 ? 

2 个答案:

答案 0 :(得分:1)

我还没有使用throttle,但我的理解如下:

您应该在使用throttletakeLatest的同一位置使用takeEvery

例如:

// 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)

我希望这对你有帮助。

答案 1 :(得分:0)

throttle =>关于第一个论点:

ms:Number - 时间窗口的长度(以毫秒为单位),在此期间将忽略操作操作开始处理后

我相信,计时器在调用操作后立即开始,我们不关心此任务的完成情况。 (应该更好地阅读文档,我的不好)