Sextant
Sextant copied to clipboard
feature: Provide an initialization hook for when the VM/view is going to be added to the stack/pushed
Is your feature request related to a problem? Please describe. It's related to usability and improving of lifecycle.
-
WhenActivated
happens too late on the VM/View cycle to start performing operations, such as loading data at VM level, setting up bindings in the view. The order of execution can be seen here:
ViewModel Constructor
View Constructor: 691 milliseconds
View OnAppearing: 1172 milliseconds
ViewModel WhenActivated: 1180 milliseconds
View WhenActivated: 1192 milliseconds
- Due to the late
WhenActivated
execution as stated above, for my case I exposed aViewModelDidBind
, which is a simplethis.WhenAnyValue(v => v.ViewModel)
exposed on my view base, so there I can start invoking commands, earlier. It does execute only once, when the viewmodel is set on that view instance, that differs from theOnAppearing
and theWhenActivated
cause both will be executed every time the view/viewmodel gets displayed. TheViewModelDidBind
works for my purpose of starting things earlier in the flow (gets executed right after the view constructor) as follows:
View ViewModelDidBind: 705 milliseconds
Describe the solution you'd like For performing operations/bindings I'd say I could start them right away when the view/viewmodel is added to the stack, that is a good earlier moment to setup things.
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 adding that into 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 "initialized" it could perform the needed operations accordingly.
Additional context
Relates To: https://github.com/reactiveui/ReactiveUI/issues/1116