等到 take 完成的动作不起作用(redux saga)

Wait until action finished by take doesn't work (redux saga)

我正在使用 redux-saga 和 redux 来处理 react 中的异步进程,但是 put&take 不起作用。知道为什么吗?

在 saga 的生成器函数中,我通过 put 调度动作 test-action。 然后我想等到动作完成,所以我尝试通过take来做,但是没有调用take

在redux-devtool中,我可以发现test-action肯定是调度了。

function* firstActionSaga(){
  // dispatch secondAction
  yield put(secondAction())

  // If secondAction finished, the below line should be called.
  yield take("SECOND_ACTION")

  console.log("second action finished.")
}

function* rootSaga() {
 yield all([

   // Wait for firstAction, and start firstActionSaga
   yield takeEvery(FIRST_ACTION, firstActionSaga)
])
}

预计

  1. 等待firstAction,然后启动firstActionSaga
  2. 通过 put
  3. 调度 secondAction
  4. 等到 secondAction,然后做点什么。

实际

  1. 等待firstAction,然后启动firstActionSaga
  2. 通过 put
  3. 调度 secondAction
  4. take 未被解雇

终于可以用'putResolve'做我想做的事了。