Skip to content

Conversation

@quiekedei
Copy link

When propagating a state update to all subscribers, it can happen that an action is dispatched as a reaction to said state update. This action is then immediately processed and the state changes it might lead to are then communicated to all subscribers before the prior state changes.
This can lead (and has led) to unexpected (and actually impossible) state changes in the subscribers and this behavior is considered a bug in ReSwift.

Please note that the solution proposed in this PR only works when all actions are dispatched on the main thread, which is a caveat that we are willing to take since it was our default behavior anyway.


open func dispatch(_ action: Action) {
dispatchFunction(action)
guard alwaysDispatchOnMainQueue else {
Copy link

@wukerplank wukerplank Sep 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish they renamed guard to unless - would make reading code much easier.

@wukerplank
Copy link

Awesome, thanks for the changes!

Two inputs from my side:

  • The project seems to use spaces instead of tabs - we should honour that.
  • Since there are multiple combinations of boolean flags possible we should have tests.

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.

4 participants