So I've just read up on redux middleware, and it sounds great. One thing is bugging me though - the return values of the middleware.
I understand that some instances of middleware return stuff (i.e. redux-promise
) , and I get that other middleware (i.e. logging
) doesn't - and simply returns the result of next(action)
.
My issue is what happens if I want to use two pieces of middleware that both return stuff - surely they will clobber each other and I will only get the outer-most middleware's return value.
express/connect
middleware addresses this by letting middleware write its "results" to the req
and res
objects, but whats the solution with redux?
EDIT
Here is a more concrete example of my issue:
I have two pieces of middleware:
- Middleware that defers all actions being dispatched by 3 seconds. This middleware returns a function that can be called to cancel the dispatch
- Middleware that returns the number 5, because I need the number 5 for some reason.
Depending on the order I chain these two bits of middleware, the result of my dispatch(action)
will either be the defer cancellation fn, or the number 5. But how do I get both of these results?