reactiveui/Sextant

feature: Provide a destruction hook for when the VM/view is going to be popped

winterdouglas opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
It's related to usability and improving of lifecycle (preventing memory leaks).

Currently the default mechanism used to perform proper subscription/unsubscription of dependencies is the WhenActivated(disposables) provided by ReactiveUI, and that works pretty well, but it has some drawbacks on its use (specially talking about property-based platforms), for my case Xamarin.Forms. These are:

  • Disposing the subscriptions with WhenActivated like the bindings and observables present on my VM implies that the user will see a full reload when navigating back to that viewmodel.
    A good example of that is:

PeopleViewModel (list of person) and PersonDetailsViewModel (shows the details of a specific person).

When navigating from the list to the details the subscriptions will be destroyed, so imagine I had scrolled the list, when I pop back to the list, the scrolling position won't be the same anymore, the items will be reloaded and the user will see a full refresh on the screen while it's not needed. Now, thinking on the perspective of the person detail, that makes sense to unsubscribe from it's observables/binding, cause that was popped, and there's no chance the user will return to that same instance of view/viewmodel.

Describe the solution you'd like
I expect that my observables/bindings should be destroyed only when that view/viewmodel is not on the stack anymore (no matter if it was popped, removed, etc), so I'd guarantee that the user won't be reaching that instance of the view/viewmodel anymore (like in the example I presented), so it could be securely freed as on a new push, a new instance of each of them will be created and added to the stack.

Describe alternatives you've considered

Describe suggestions on how to achieve the feature
What I can think right away is to expose a (potentially new) interface on Sextant and then to call it accordingly when removing from the stack, and then let the view/viewmodel that's interested on it to implement that interface that would have that new "hook". Knowing it's being removed from the stack it could perform the needed operations accordingly.

Hey @winterdouglas 👋,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider contributing financially.

https://opencollective.com/reactiveui

PS.: We offer priority support for all financial contributors. Don't forget to add priority label once you start contributing 😄

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.