Odonno / ReduxSimple

Simple Stupid Redux Store using Reactive Extensions
http://www.nuget.org/packages/ReduxSimple/
MIT License
143 stars 19 forks source link

Subscribe does not fire for initial State #42

Closed Feroks closed 5 years ago

Feroks commented 5 years ago

I am having a singleton Store that i inject into my ViewModel. When i navigate to it i am subscribing to changes in store like this.

Store
.ObserveState(x => x.IsEnabled)
.Subscribe()

My problem is that it does not fire for initial value, because you are using Subject<TState>() instead of BehaviorSubject<TState>(initialState). Is this by intention or not? As of now, my only alternative is to use .StartWith(Store.State.IsEnabled), but this is not that pretty.

Odonno commented 5 years ago

Hi @Feroks

Indeed, the initial value of State was never observed. It wasn't really intentional because I was thinking that it is up to the developer to separate the initialization of a component (using the initialState) and then update it using the ObserveState.

But now I realise that you can handle the initialization and the update logic inside the Subscribe method.

I will make the changes in the source code. BTW, thank you for the BehaviorSubject shortcut. I never knew we could do that.

Odonno commented 5 years ago

Ey @Feroks

I updated the nuget package so you can now upgrade to version 2.0. This issue is a breaking change so I moved from 1.2 to 2.0.

Thank you for your feedback.

https://media.giphy.com/media/l41lUjUgLLwWrz20w/giphy.gif