subscribe listener can get action param? #1057

Closed
cloudIC opened this Issue Nov 19, 2015 · 3 comments

Comments

3 participants
@cloudIC

cloudIC commented Nov 19, 2015

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

This comment has been minimized.

Show comment
Hide comment
@gaearon

gaearon Nov 19, 2015

Collaborator

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:

https://github.com/rackt/redux/issues/347
https://github.com/rackt/redux/issues/580

Collaborator

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:

https://github.com/rackt/redux/issues/347
https://github.com/rackt/redux/issues/580

@gaearon gaearon closed this Nov 19, 2015

@gaearon gaearon added the discussion label Nov 19, 2015

@whatifif

This comment has been minimized.

Show comment
Hide comment
@whatifif

whatifif 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.

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

This comment has been minimized.

Show comment
Hide comment
@gaearon

gaearon Dec 5, 2015

Collaborator

This is exactly the use case for middleware.

Collaborator

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