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

subscribe listener can get action param? #1057

Closed
cloudfroster opened this issue Nov 19, 2015 · 3 comments
Closed

subscribe listener can get action param? #1057

cloudfroster opened this issue Nov 19, 2015 · 3 comments

Comments

@cloudfroster
Copy link

why subscribe can not get action.I don't know whether the following is a good idea

listeners.slice().forEach(listener => listener())
//to
listeners.slice().forEach(listener => listener(action))
@gaearon
Copy link
Contributor

gaearon commented Nov 19, 2015

Subscribers should react to the new state, not to what happened.
This is important for ensuring consistency.
You can use custom middleware to get around it.

Please see:

#347
#580

@whatifif
Copy link

whatifif commented Dec 5, 2015

In my case, the action is sent to the server after "dispatch" is done. The server has same Redux store as client and the action changes the server state to synchronize with client state.
In this case, it is convenient if "subscribe listener" is given the action parameter.

Of course, this can be achieved using middleware. But it may be better if this is a default way of "subscribe listener".

By preparing the same Redux store in server as well as in client, server-side state manipulation becomes same as client.

In this concept, the action is a state synchronizer which is transferred among all the connected client including the server.

@gaearon
Copy link
Contributor

gaearon commented Dec 5, 2015

This is exactly the use case for middleware.

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

No branches or pull requests

3 participants