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

Forbid getState() and subscribe() while the reducer is being called #1568

Closed
gaearon opened this Issue Apr 2, 2016 · 3 comments

Comments

2 participants
@gaearon
Copy link
Contributor

gaearon commented Apr 2, 2016

This is an anti-pattern, first found here: reduxjs/redux-devtools#264.

I think we should protect against store.getState() calls from inside the reducer. They make the reducer impure, and you can always pass the store state down as the third argument if this is something you’re interested in.

I think we should forbid this pattern just like we forbid dispatch() while the reducer is running.

Same goes for subscribe() which should never be called from inside a reducer.

A pull request to implement this is welcome.

@gaearon gaearon added the help wanted label Apr 2, 2016

@gaearon gaearon referenced this issue Apr 2, 2016

Closed

Redux 4 breaking changes #1342

8 of 8 tasks complete
@mjw56

This comment has been minimized.

Copy link
Contributor

mjw56 commented Apr 2, 2016

I can work on this.

@gaearon

This comment has been minimized.

Copy link
Contributor Author

gaearon commented Apr 2, 2016

👍 Don’t forget the unsubscribe too (the function being returned from subscribe()).

@gaearon

This comment has been minimized.

Copy link
Contributor Author

gaearon commented Apr 2, 2016

Thanks! Let’s continue the discussion in #1569.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment