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

Pass state to listeners as an argument? #1513

Lucretiel opened this Issue Mar 11, 2016 · 3 comments


3 participants

Lucretiel commented Mar 11, 2016

This seems so straightforward and obvious I feel like I'm missing some reason it isn't done this way. Why don't listeners accept the new state as an argument?

let unsubscribe = store.subscribe(state => {

This comment has been minimized.


merk commented Mar 11, 2016

Just use getState on the store.

let unsubscribe = store.subscribe(() => {
   const state = store.getState()

// ...

This comment has been minimized.

Lucretiel commented Mar 11, 2016

I know, but why require the extra step? Especially considering how prevalently injection/control inversion is used elsewhere in redux?


This comment has been minimized.


gaearon commented Mar 11, 2016

This has been discussed before: #303. subscribe() and getState() are orthogonal on purpose so if you “override” one in a store enhancer, you don’t need to override the other.

In any case, having just the new state is not very useful. You’ll probably want the previous state too. And not just the previous state—probably a specific part you care about. At which point you might as well write your own helper to do this.

See #303 (comment) for more details.

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