Skip to content
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

Which middleware runs the reducer when there are two middlewares. #32

Closed
NimmiW opened this issue Mar 13, 2017 · 4 comments
Closed

Which middleware runs the reducer when there are two middlewares. #32

NimmiW opened this issue Mar 13, 2017 · 4 comments

Comments

@NimmiW
Copy link

NimmiW commented Mar 13, 2017

image

This is my code. I was going through this tutorial

https://www.youtube.com/watch?v=DJ8fR0mZM44&index=19&list=PLoYCgNOIyGABj2GQSlDRjgvXtqfDxKm5b

Which middleware runs the reducer when there are two middleware? I have logger and Error middleware. Is there a order or something like that?

@NimmiW
Copy link
Author

NimmiW commented Mar 13, 2017

I am new to redux and react. therefore pls excuse any fault in my question :)

@willrstern
Copy link
Collaborator

When you do applyMiddleware(logger, error), that means that the reducer will go through logger then error in order for each change event. either of those can modify the new state or terminate the event by not calling next - in which case, the next reducer never fired.

So, in this case, a logger would log every action and call the next middleware
the error middleware will try a next action and error if it doesn't work, it will log the error and not continue on with next

So essentially, every middleware fires every time. That's why you add the switches in there - so each middleware only responds to the actions that it cares about.

@NimmiW
Copy link
Author

NimmiW commented Mar 13, 2017

Thank you very much @willrstern I got that :)

@willrstern
Copy link
Collaborator

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants