Reputation: 8274
case 1
say I dispatch({type: TEST_EVENT})
in UI with useEffect
, and both my saga and reducer are listening to the same event. Who will get it first.
case 2
say I dispatch({type: TEST_EVENT})
in UI with useEffect
, then saga listening to it, then in saga I do yield put({type: 'TEST_EVENT_1'}
, then reducer (if listening TEST_EVENT_1
) will be able to receive it. Could someone confirm this?
Upvotes: 1
Views: 744
Reputation: 102457
case 1: From the redux-saga
middleware source code, we know if both saga and reducer are listening to the same action type. The reducer will get the action firstly.
case 2: The recommended workflow is: dispatch SOME_EVENT
action => watcher saga => worker saga => do something(call API, computation, etc..) => dispatch SOME_EVENT_FULFILLED
/SOME_EVENT_REJECTED
action to reducer.
Upvotes: 1