Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Provide an initialization hook for when the VM/view is going to be added to the stack/pushed #225

Open
winterdouglas opened this issue May 22, 2020 · 1 comment

Comments

@winterdouglas
Copy link
Contributor

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 a ViewModelDidBind, which is a simple this.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 the OnAppearing and the WhenActivated cause both will be executed every time the view/viewmodel gets displayed. The ViewModelDidBind 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

@RLittlesII
Copy link
Member

Relates To: reactiveui/ReactiveUI#1116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants