Closed wizd closed 4 years ago
Store.Select
returns an IObservable
so your call to Subscribe
gives you an IDisposable
that you can just dispose. Learn more about this here (it's general Rx stuff, not specific to this framework).
Thank you very much! I use CancellationToken to do the unsubscribe, its much simpler.
Indeed, you can. I never thought about unsubscriptions on this project but it is a mandatory feature. In angular projects, we usually use a custom operator named untilDestroyed
. I will surely add a similar feature here.
Thanks for your help @bddckr
@wizd Done. With the v3.5 of ReduxSimple, you will now be able to use a UntilDestroyed
operator to automatically clean subscriptions once the view is unloaded.
Because this operator strongly depends on the View Engine, only UWP is supported for now. I think it would easy to support other View Engine but I need to find time for that. If you are working on a View Engine other than UWP, feel free to push a PR ;)
Note that if you look at the Sample app, you will see that some subscriptions do not use this operator. It is because XAML events are already unsubscribed when the XAML element is disposed.
Also note that you can find this operator in the ReduxSimple.Uwp
package.
App.Store.Select(state => state.IsChanged) .Subscribe(w => { // do things, then unsubscribe }
how to unsubscribe state changes when work is done?