-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Pass action/type to subscribed listener? #347
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
Comments
Can you expand on the use case? |
I use it for logging (in my own subset of Redux), but that's a typical case for middleware. |
I wanna integrate my redux app with openlayers map. For example, action CHECK_OBJECT dispatched with object_ id as payload. Then reducer handles that action and changes state. After that I need to show that checked object on the map. One way I see is to catch up actions after all reducers are applied (via subscribe with action as argument), get object from new state and then add that object on the map. Openlayers is not react-compatible through such integration will be kind of hacking anyway. Maybe there are much better way to do that integration? |
What data do you need to grab from action? In other words why doesn't this work for you: this.props.dispatch(checkObject(id));
this.props.dispatch(showOnTheMap(id)); |
@gaearon I think it is bad idea because then the code managing openlayers should be in the action creator or in the reducer. Also the openlayers map and the react component are logically different and I think that the react component should not calling My example below was a bit simplified. In fact I also need to synchronize the map state (zoom, extent and other properties) and the redux state. In other words the redux state changes should cause the map state changes and otherwise. In my mind there should be some kind of central hub between redux and openlayers. If the hub receives an event from the openlayers then the hub dispatches action to the store. And otherwise, if the hub (subscriber) receives action then it send change to openlayers. Here is a little dirty diagram. I think all the communications between redux and openlayers should going through that map manager. It is easy to control and maintain. And if subscriber will receive dispatched action then it will be possible to realize such functionality. As to the middleware, it handles the action before applying the reducers. And I need to handle action after applying reducers to get new modified state. Actually I can apply the reducers to the cloned state manually but it's kind of freaking :) |
No, you can write middleware to execute code after the dispatch occurs. Example from the new docs: function logger({ getState }) {
return (next) => (action) => {
console.log('will dispatch', action);
// Call the next dispatch method in the middleware chain.
let returnValue = next(action);
console.log('state after dispatch', getState());
// This will likely be the action itself, unless
// a middleware further in chain changed it.
return returnValue;
};
} |
Oh sorry I overlooked it. Exactly what I need. Thanks. |
It would be cool if the subscribers will know what action has caused changes. What do you think about it?
The text was updated successfully, but these errors were encountered: