freeletics / RxRedux

Redux implementation based on RxJava
https://freeletics.engineering/2018/08/16/rxredux.html
Apache License 2.0
567 stars 34 forks source link

Action observation order for reducer and side effects #92

Open gwright opened 5 years ago

gwright commented 5 years ago

The FAQ regarding reducers and side effects says:

Technically speaking Reducer gets every Action from upstream before the registered SideEffects. The idea behind this is that a Reducer may have already changed the state before a SideEffect start processing the Action.

In looking through the code this behavior seems to hang entirely on the fact that PublishSubject stores its subscribers in an array, multicasts events to subscribers in array order, and the reducer is the first subscriber. I don't think that behavior is part of the public API for PublishSubject. For example, see https://github.com/ReactiveX/RxJava/issues/1662#issuecomment-54387758

I'm still learning about RxJava and am even more naive about RxRedux so I may be missing something here. If my observations are correct, I think the implementation of ObservableReduxStore#subscribeActual should be refactored to ensure actions are reduced before being multicast to the side effect subscribers.