Redux 传奇:在错误为真时执行所有操作
Redux saga: take every action where error is true
是否可以指定操作是否将其错误字段设置为 true?
const response = function*() {
yield takeEvery("CLIENT_RESPONSE", handleResponse);
}
但是,我们不知道 CLIENT_RESPONSE
类型的操作是否将其错误字段设置为 true。
我知道我可以在 handleResponse
中检查这个,但这似乎比它应该做的更多。例如,handleResponse
可能会变得复杂,因为对于非错误和错误情况我都需要编写大量代码(即我想为两种情况使用不同的处理程序)。
那么有没有一种方法可以指定仅在错误设置为 true 时执行该操作?
根据 Saga API reference,takeEvery
的模式 (第一个参数) 可以是 String
,Array
或 Function
。
你可以通过传递一个函数来实现你想要的:
const response = function*() {
yield takeEvery(action => (action.type === "CLIENT_RESPONSE" && !action.error), handleResponse);
}
是否可以指定操作是否将其错误字段设置为 true?
const response = function*() {
yield takeEvery("CLIENT_RESPONSE", handleResponse);
}
但是,我们不知道 CLIENT_RESPONSE
类型的操作是否将其错误字段设置为 true。
我知道我可以在 handleResponse
中检查这个,但这似乎比它应该做的更多。例如,handleResponse
可能会变得复杂,因为对于非错误和错误情况我都需要编写大量代码(即我想为两种情况使用不同的处理程序)。
那么有没有一种方法可以指定仅在错误设置为 true 时执行该操作?
根据 Saga API reference,takeEvery
的模式 (第一个参数) 可以是 String
,Array
或 Function
。
你可以通过传递一个函数来实现你想要的:
const response = function*() {
yield takeEvery(action => (action.type === "CLIENT_RESPONSE" && !action.error), handleResponse);
}