I have a saga which is listening to an action. And when this action is dispatched it performs a blocking call.
The problem is that a lot of actions (same actions) are dispatched in the same time and my saga can't take all the actions. But I need to process each action synchronously.
I know this is a known problem in redux-saga documentation : My Saga is missing dispatched actions
But the fact is that I can't use a fork since I really need the previous call to be over before processing a new one.
Here is my code :
export function* readProducts() {
while (true) {
const {
payload: { tags },
} = yield take(RFID__ADD_PRODUCT);
// sequential add of each item
for (const tag of tags) {
yield call(addProductViaRfid, tag);
}
}
}
Does anyone have a solution ?
Well, no matter what you pass to dispatch , it is still a single action. Even if your action is an array of objects, or a function which can then create more action objects!
The effective result is the same: you can now dispatch multiple actions from one dispatch call. Here we have two examples using React Redux's connect decorator and React's JSX, the first using the multiAction action creator, the second using just an array. Note: These examples use a Stateless Functional Component.
put is another effect provided by redux-saga which can be used to dispatch actions in a saga. So this instructs the middleware to dispatch an action COFFEE_DONE to the store.
You can create a buffering action channel and take actions from it.
export function* readProducts() {
const addProductRequests = yield actionChannel(RFID__ADD_PRODUCT);
while (true) {
const {
payload: { tags },
} = yield take(addProductRequests);
// sequential add of each item
for (const tag of tags) {
yield call(addProductViaRfid, tag);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With