Skip to content

Add an optional 'callback' to dispatch #1096

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

Closed
wants to merge 1 commit into from

Conversation

mhodgson
Copy link

@mhodgson mhodgson commented Dec 3, 2015

Called when all listeners have resolved.

This enables a dispatch caller to run a callback once all changes from an action have been flushed and rendered (in my case to the DOM via React).

I didn't include a promise implementation here since I don't know what people's preferences are.

Thoughts about this? I have a specific use case around DOM selection binding that this enables.

See reduxjs/react-redux#208 for related change to react-redux.

@mhodgson
Copy link
Author

mhodgson commented Dec 4, 2015

@gaearon @ellbee Any thoughts here? This is a non-breaking change with no effect on the existing API and enables callbacks that need to occur after all updates are complete (i.e. inspecting selection state, taking screenshots, re-enabling listeners, etc.).

@just-boris
Copy link
Contributor

If you want to get this working, you should pass callback through all store decorations in compose method.

@gaearon
Copy link
Contributor

gaearon commented Dec 4, 2015

I don't think we want to get this in.
The store acts like a very simple event emitter.
We don't want to make it more complex.

I don't know what a better solution would look like but it shouldn't involve Redux.
It's similar to how you wouldn't modify Rx or EventEmitter to fix a similar problem.
It's just not their concern.

@gaearon gaearon closed this Dec 4, 2015
@mhodgson
Copy link
Author

mhodgson commented Dec 4, 2015

@gaearon as far as I can tell there is no way to use redux for this use case then. Why is having a callback for when a dispatch is 'complete' outside of the scope of Redux?

@gaearon
Copy link
Contributor

gaearon commented Dec 4, 2015

Because dispatch is synchronous. It doesn't make sense to add an async callback to a synchronous method. Asynchrony is an implementation detail of your subscribers and should be dealt with on their level—whether in React Redux, React itself, or via some other means.

@mhodgson
Copy link
Author

mhodgson commented Dec 4, 2015

Thanks for the explanation. I think I see a path forward by adding a decorator outside of @connect and overriding the listener trigger in Connect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants