-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Redux middleware example causes confusion #3858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The middleware isn't trying to "always" run the const cancelTimer = dispatch({type: 'increment', meta: {delay: 5000}});
// later
cancelTimer(); Returned values are important, because a middleware can return anything it wants from |
@markerikson I don't think you can ALWAYS call to cancelTimer() if you have MORE than one middleware in the chain. The dispatch() only return the returned value from the FIRST middleware in chain. So, how to access the returned value of all seven chained middleware? |
That's how Redux middleware work. Any middleware may substitute its own return value. If a middleware is written correctly, it should pass later return values forward, ie, However, any middleware in front of that may also substitute its own return value, delay the return value, not return anything, etc. So, it's a question of how the middleware in the chain are cooperating with each other. But yeah, this middleware itself is written correctly. Trust me on this :) |
@markerikson thanks for your explanation. It would be better if that flexibility is described more clearly in your document. |
Rewriting the existing "Basics/Advanced" tutorial is literally what I'm working on right now :) See #3854 . |
What docs page needs to be fixed?
One of the seven examples on redux middleware section causes me confused. It is the timeoutScheduler.
https://redux.js.org/advanced/middleware#seven-examples
What is the problem?
I don't think that the cancel() function will ALWAYS be called. The only way we can call this function is register timeoutScheduler as first middleware on the chain then execute store.dispatch()().
What should be changed to fix the problem?
I think we should remove that out of the examples. Since the returned value is NOT important when using middleware.
The text was updated successfully, but these errors were encountered: