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
Make the store.subscribe pass the action to the listener #1971
Comments
The design philosophy is that subscribers react (no pun intended) to changes to state, not to specific actions. |
This has been discussed about seven times before. Could you please be so kind to search the issues? I could drop some links when I'm home—I'm on the cell right now. Basically we don't want to do this because there is actually no guarantee that we will call subscribers after every action. For example, if a subscriber causes a nested dispatch, we reserve the right to skip the nested notifications and only notify the subscribers when the outermost dispatch ends. Which means that if the action was passed, you would miss one. I hope this helps! If you search the issues you'll find some advice about how to approach problems that require this. Middleware is a common solution to having logic depend on actions rather than the state. |
Thanks a lot and sorry for the inconvenience! I already searched the issues before opening this one, but with almost 2k of them in stock it's pretty hard to find rather generic topic like this 🙈 |
Yeah, the FAQ really needs a "Design Decisions" section for stuff like this (which is in my list of updates to add, at #1785 ). |
@andywer - +1 @gaearon - Is being a bit obtuse towards guys who have recently being exposed to this. There are plenty of issues @gaearon, please be patient. Guessing the right keyword is not natural to most of us. I ran into this here: #2584 I get what you are saying about not having to deal nested dispatches because you basically don't want to become a message bus, but you should at least allow the meta data to flow through. Let's please just make sure we are grounded in the fact that we are still coding in javascript and not haskell. |
@fir3pho3nixx Man, there should be a place for things. It's called separation of concerns. If you want to pass do all in one place write own lib for all your needs. Redux should be clean and simple and it solves its use cases. |
@TrySound - My use case is because of angular and the fact that view binding to our store is triggered on each state change(admittedly further down the line). Our listener is being debounced and we use reselect on the view. We are building a calculation engine, so we care about purity of data and we also use Saga's. We also have complex graphs in our store because we trace each calculation. I am thinking along the same lines as you, I want to separate things even more. I need a new hook. |
It's not a hook. It's a hack. I use redux with angular.js and it's okay. Nothing special here. Want to react on actions - use middleware. Want event bus, use streams (most or rx). You may even use 'em together like |
@fir3pho3nixx : per the prior comments, the intended usage of Redux is that subscribers should be reacting to the current state and changes from the previous state, not the actions themselves. As @TrySound just commented, if you do want to have logic that hooks into dispatched actions, the right place is middleware. Existing general-purpose side effects libraries like |
First of all, thanks for replying, secondly thanks for putting up with me. I am not sure you got this right you know? You have a functionally pure store that pummels the bejesus out of angular for irrelevant data updates when using complex graphs. I inherited this paradigm. I just have pureist views on the runtime. If you are doing this in javascript, you're using the wrong language. |
Time for Fable anyone. :) |
For anyone still looking for that feature |
tldr; Is there a special reason why
store.subscribe()
does not pass the dispatched action to the listeners? I will open a PR if you feel comfortable passing down the action.Use case
We are using the react-router-redux and I would like to subscribe to the store for a short time, so I get to know if a route change is triggered. It would be highly desirable to not only be informed that some action has just been dispatched, but what action has been dispatched, so I can immediately check if this action is of any interest to me (route change) and react to that event if so.
Cheers!
The text was updated successfully, but these errors were encountered: