This question is locked. New answers and comments are not allowed.
I have been attempting to leverage the "data-init", "data-show", etc... attributes for my views to execute specific functionality at specific view lifetime events. However, I ran into a snag when I attempted to execute the view-model method directly. It turns out that the context of "this" in the view-model's init method is not the view-model itself when called from the "data-init" attribute. For example, I created a "myViewModel" view-model that contains an "init()" function. If I define the associated view's data-init function as data-init="myViewModel.init()" the view-model's init function is called but the "this" context is some object other than the expected view-model. I also tried setting the "data-model" attribute to be "myViewModel" but this did not seem to help. I have been able to work around this issue by creating associated "onMyViewModelInit()" functions outside of the scope of the view-model which in turn calls the "myViewModel.init()" which gives "this" the proper context. However, this seems kind of hacky.
Also, concerning the view's lifetime events I am confused as to why the "before-show" event is executed prior to the "init" event. This seems backwards especially since the "before-show" event is executed prior to every "show" event but the "init" event is only ever executed on the initial creation of the view. I had expected that the event order would be "init" -> "beforeShow" -> "show" -> "hide" -> etc... but this is not the case. Any chance that these events will be re-ordered as described above? This would greatly simplify my view initialization logic. Also, is there an event defined for "destroy" or "kill" or anything similar to allow cleanup prior to deleting a view?
Also, concerning the view's lifetime events I am confused as to why the "before-show" event is executed prior to the "init" event. This seems backwards especially since the "before-show" event is executed prior to every "show" event but the "init" event is only ever executed on the initial creation of the view. I had expected that the event order would be "init" -> "beforeShow" -> "show" -> "hide" -> etc... but this is not the case. Any chance that these events will be re-ordered as described above? This would greatly simplify my view initialization logic. Also, is there an event defined for "destroy" or "kill" or anything similar to allow cleanup prior to deleting a view?