redux-saga: How to create multiple calls/side-effects programmatically for yield?
This might work aswell https://github.com/redux-saga/redux-saga/tree/master/docs/api#alleffects
function* mySaga() {
const { customers, products } = yield all({
customers: call(fetchCustomers),
products: call(fetchProducts)
})
}
Please note that call
effect doesn't call anything at the time.
It just creates Plain JavaScript Object and returns. So what you want is not so difficult.
import { call } from 'redux-saga/effects'
const params = ['abc', 'def', 'ghi']
const responses = yield params.map(p => call(fetch, p))
So according to the redux saga docs as of 11/17/2019 its says in order to make it execute in parallel you need to use all()
yield all( arrayOfSomething.map( eachSomething => call( myFunction, eachSomething ) ) )
or if you want to compute some stuff before making your call
yield all( arrayOfSomething.map( eachSomething => {
// do some computations
// important you return the function which is automatically done
// for you in the one line map, this has gotten me a few
// times when I am just coding fast
return call( myFunction, eachSomething ) )
} )