javascript - 等到 take 完成的操作不起作用(redux saga)
问题描述
我正在使用 redux-saga 和 redux 来处理 react 的异步过程,但是 put&take 不起作用。知道为什么吗?
在 saga 的生成器函数中,我test-action
通过put
. 然后我想等到动作完成,所以我尝试通过 来做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)
])
}
预期的
- 等待 firstAction,然后启动 firstActionSaga
- 调度 secondAction 由
put
- 等到 secondAction,然后做点什么。
实际的
- 等待 firstAction,然后启动 firstActionSaga
- 调度 secondAction 由
put
take
没有被解雇
解决方案
最后,我可以使用“putResolve”来做我想做的事。
推荐阅读
- git - 如何删除 git repo 中的重复文件?
- excel - 如何在excel中仅提取月末日期的数据?
- python - 根据其他列的值为 Pandas Dataframe 创建列
- django - 为什么在 Django i18n 中使用 domain.com 而不是 domain.com/en/ 时会出现错误 500?
- javascript - React Memo 更新父组件状态
- c - 无法在 Visual Studio C 程序上使用 OCILIB 连接到数据库
- python - 服务 attention_ocr 模型时出错 ("error": "Expected one or two output Tensors, found 17")
- azure - Azure 负载均衡器 - SSRS 横向扩展
- php - 从php中的数组中删除每个第3个和第4个元素
- xml - How to check empty node using FreeMarker