Skip to content
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

setState should support callbacks, same as the typical react setState #544

Open
steventnorris-40AU opened this issue Apr 10, 2018 · 1 comment

Comments

@steventnorris-40AU
Copy link

Currently, reflux setState does not support a callback. I believe expected functionality here would be that it worked like or better than the typical React setState.

Suggestion:
Set expected completions based on number of subscribed components.
While looping setState for all subscribed components, fire off a callback on that component's setState indicating it is complete.
When all completions are reached, fire the callback for the reflux store's setState.

I believe this could also be wrapped as a promise instead of a callback. Honestly, I'm not sure why the normal React setState is a callback and not a promise.

@BryanGrezeszak
Copy link
Contributor

BryanGrezeszak commented Apr 21, 2018

Reflux's this.setState does not have a callback because it changes its store state immediately. React only has callbacks as a workaround for the fact that it doesn't. It would be very awkward (and even confusing) to implement a workaround that "works around" a problem that doesn't actually exist in Reflux.

As for your suggestion that it instead call back when all subscribing components have updated their state: that is a major violation of the single most fundamental principle of flux itself (one-way data flow).

If your store logic depends upon knowing the state of subscribed components then you're doing something very different from flux!

However, I definitely see that this should be documented so that people know they don't need callbacks, and will get that in the docs soon.

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

No branches or pull requests

2 participants