Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Redux is great but major feature is missing... #1300
Redux is a great modeling pattern that I am sure will continue and grow...
However Redux is missing a critical part as currently it focuses more on the producer and less on the consumer.
currently when an action is produced, all subscribers will receive the callback, however if you ever developed a large application, or worst yet, had to jump into someone else's code you know that the biggest issue is finding your way around. And so if I look at a reducer which is switching on some list of action, I would like to be able to see all the places in the code base that "cares" about a particular (like we always do with events), just right click on the action in your favorite IDE and select find usage.
now I understand that with reducers you can divide the application to multiple smaller reducers to so its easier to find things... BUT, if you are going to refactor a line of code, you want to make sure all subscribers that rely on it will not explode...
The cleanest way to get that is simply to pass the action to the subscriber as in:
and we can find all places in the code that refer to Consts.FOO when we refactor...
It will be much easier to reason about how changes propagate in a large application if we can get the action to be passed to the subscribers.
The second point (which may or may not be valid) is why isn't the store reference passed as well just to save a single line of code: store.getState();
so instead wouldn't that be better:
If we already have a subscriber we might as well use it to pass relevant parameters.
Thanks for a great framework and hope we can get it even better,
Sean - founder of http://DigitalSignage.com
Can you please explain on a specific scenario how that would make code easier to understand? In Redux you should re-render UI based on current state, not the action. By the time the state is returned from the reducer, the action doesn't matter anymore. For debugging, you can use redux-logger:
Also this has been discussed in quite a few issues:
Please see #303.
In general it’s best to search for issues first
I don't understand what kind of code you are refactoring. If subscribers can't know about the action in the first place, how does passing it help refactoring? Some specific real-world examples will help.
I stumbled upon this and also found a situation where I want a component to react to action, not state.
The list of members in an organization is nothing I want to store in the global state, doesn't make any sense. However, I want my component to know when the thunk dispatches a "success" action so it can do something (force a re-render).
Why does the component need to re-render if state has not changed?
On 11 March 2016 at 11:40, Sam firstname.lastname@example.org wrote:
@ffxsam From what I understand is that you want to have a component react directly on the response of an async action rather than storing that data in the state and having the component react to a state change?
That would break the idea of a unidirectional data flow because you'd be bypassing the reducers and have a component tightly coupled to an external entity (your API responses). This kind of defeats the purpose of using redux (or a single state atom). If it's a whole lot of data you can look into paging, memoizing etc. Or just clean up the state when you leave the module/page and don't need the data anymore and then refetch from server or cache on next visit.
Just a couple of ideas :)