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

Question: Do both Reducers and Effects handle Actions? #837

Closed
bhaidar opened this issue Feb 17, 2018 · 4 comments
Closed

Question: Do both Reducers and Effects handle Actions? #837

bhaidar opened this issue Feb 17, 2018 · 4 comments

Comments

@bhaidar
Copy link

bhaidar commented Feb 17, 2018

Hi
I'm learning ngrx store and I'm new.

I know that Reducers are like Action Listeners. Then I learned that Effects can also handle Actions. I'm a bit lost here. Isnt the case that Reducers are the only ones who can handle Actions and change State?

Thanks

@brandonroberts
Copy link
Member

Reducers use actions to change state. Effects are used to listen for actions and return new actions

@bhaidar
Copy link
Author

bhaidar commented Feb 18, 2018

Hi @brandonroberts what if both Reducers and Effects listen to the same Action. Who runs first? So as an example an Effect might listen to an Action to load data from server. This action doesn't change State so no need to listen 5o it by a reducer. Effects listen to the action and loads data from server and then fires an event with a payload of data received and raises an event for the reducer to catch and update state accordingly? That's how it works?

Thanks

@brandonroberts
Copy link
Member

Yes. More specifically all actions hit all reducers first, then the action is passed to the effects.

@bhaidar
Copy link
Author

bhaidar commented Feb 18, 2018

Thanks a lot @brandonroberts !

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