Skip to content

Add an optional 'callback' to dispatch#1096

Closed
mhodgson wants to merge 1 commit into
reduxjs:masterfrom
GoBoundless:master
Closed

Add an optional 'callback' to dispatch#1096
mhodgson wants to merge 1 commit into
reduxjs:masterfrom
GoBoundless:master

Conversation

@mhodgson

@mhodgson mhodgson commented Dec 3, 2015

Copy link
Copy Markdown

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

mhodgson commented Dec 4, 2015

Copy link
Copy Markdown
Author

@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
Copy Markdown
Contributor

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

@gaearon

gaearon commented Dec 4, 2015

Copy link
Copy Markdown
Contributor

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

mhodgson commented Dec 4, 2015

Copy link
Copy Markdown
Author

@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

gaearon commented Dec 4, 2015

Copy link
Copy Markdown
Contributor

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

mhodgson commented Dec 4, 2015

Copy link
Copy Markdown
Author

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