Sagas started with runSaga can't take actions from Saga started with the middleware
See original GitHub issueLet’s say I have 2 sagas:
- simple api saga that was provided to middleware:
function* apiSaga(getState){
while(true){
const action = yield take('API')
const { result, error } = yield call(requestApiService, action)
const [reqType, successType, failType ] = action.types
yield put({ type: reqType, action })
if(error) {
yield put({ type: failType, error })
} else {
yield put({ type: successType, result})
}
}
}
- another saga, that I want to call with
runSaga
method:
function* routeResolveSaga(getState){
yield put({ type: 'API', ..... types: ['ACTION_REQUEST', 'ACTION_SUCCESS', 'ACTION_FAIL'] })
yield take(['ACTION_SUCCESS', 'ACTION_FAIL'])
}
When I call
runSaga(function*(getState){
yield call(routeResolveSaga, getState)
}(store.getState), storeIO(store))
apiSaga
takes API
action, after request is puts new action ACTION_SUCCESS
or ACTION_FAIL
, routeResolveSaga
is waiting to take it, but nothing happens.
Maybe I have missed something?
Issue Analytics
- State:
- Created 8 years ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
Troubleshooting | Redux-Saga
It will put the application into an infinite loop because take() only creates a description of the effect. Unless you yield it for...
Read more >redux-saga cannot catch actions dispatched by store enhancers
run(sagas); ). From redux-saga docs it seems that saga must be run after applyMiddleware, so I cannot make saga run before enhancer. Is...
Read more >Redux Toolkit's new listener middleware vs. Redux-Saga
Redux Toolkit's new listener middleware is a great alternative to Redux Saga, with a few caveats - learn all about it in this...
Read more >Using runSaga | redux-saga
Dynamically starting Sagas with runSaga. The runSaga function allows starting sagas outside the Redux middleware environment. It also allows you to hook up ......
Read more >Redux Saga Testing Using Runsaga Not Updating The State
From the saga examples it looks like they all use a Sagas started by runSaga can't see actions from sagas started by the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just put together a minimal example - the kicker… it works as expected! I’ll keep investigating as to why it doesn’t work in my full react app.
In my full app if i don’t “fork” it works. I think i’ll just not fork.
In the other hand, according to @butchmarshall 's example, reducers are able to take actions from the sagas started with the middleware.
So my workaround to this problem is to dispatch a new event triggered by the reducer capture so that the sagas started with
runSaga
can properly take them indirectly in a two step process. Just make sure this anti-pattern is avoided.