我有
yield race([
take('ACTION_ONE'),
take('ACTION_TWO')
])
但是我想指定ACTION_ONE
整理的条件是动作有效负载具有特定值。我怎么能这样做?
答案 0 :(得分:1)
可能你需要定义一个新的传奇来处理' ACTION_ONE'并把它放在比赛中。像这样:
function* actionOneSaga() {
let notFound = true;
while(notFound) {
const action = yield take('ACTION_ONE');
if (action.payload === 'SOME_VALUE') {
doSomethingWithYourValue(action.payload);
notFound = false;
}
}
}
然后你可以这样做:
yield race([
take(actionOneSaga),
take('ACTION_TWO')
])
答案 1 :(得分:0)
您可以在汇整中传递回调函数。
const { action1, action2 } = yield race({
action1: take(action => action.type === 'ACTION_ONE' && action.value === value),
action2: take(action => action.type === 'ACTION_TWO' && action.value === value),
})
if (action1) {
console.log('action1 fired')
}
if (action2) {
console.log('action2 fired')
}