等到 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)
])
}
预计
- 等待firstAction,然后启动firstActionSaga
- 通过
put
调度 secondAction
- 等到 secondAction,然后做点什么。
实际
- 等待firstAction,然后启动firstActionSaga
- 通过
put
调度 secondAction
take
未被解雇
终于可以用'putResolve'做我想做的事了。
我正在使用 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)
])
}
预计
- 等待firstAction,然后启动firstActionSaga
- 通过
put
调度 secondAction
- 等到 secondAction,然后做点什么。
实际
- 等待firstAction,然后启动firstActionSaga
- 通过
put
调度 secondAction
take
未被解雇
终于可以用'putResolve'做我想做的事了。