Redux: subscribe listener can get action param?

Created on 19 Nov 2015  ·  3Comments  ·  Source: reduxjs/redux

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))
discussion

Most helpful comment

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

All 3 comments

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

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.

This is exactly the use case for middleware.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vraa picture vraa  ·  3Comments

mickeyreiss-visor picture mickeyreiss-visor  ·  3Comments

rui-ktei picture rui-ktei  ·  3Comments

benoneal picture benoneal  ·  3Comments

CellOcean picture CellOcean  ·  3Comments