On view loaded and on view unload order

Hi!
I am experiencing an issue with the order of execution of the event handler actions of two views. The scenario is as follows:

I have two views in which I want to enable “Subscribe to updates” on the same data source. I do so in an action connected to the event “On view loaded”. I also want to disable “Subscribe to updates”, so I do so “On view unload”. This applies to both views.
The case is, when using this app solution and changing from one of these views to the other, the “On view loaded” of the new view will apply before the “On view unload” of the old view. I am assuming this is because the two actions are run in parallell, and the unload action is simply slower than the load action, but this causes the datasource to have “Subscribe to update” as false after the view has loaded, despite my intentions.

I have been able to solve this with a workaround by applying 200 ms sleep as an action “On view load” for both views, but this does not seem like an ideal solution.
I don’t understand why one would want “On view loaded” of one view to be able to occur before “On view unload” of another - perhaps someone could provide an argument for this? More importantly, if the order could be selected this would not have been an issue. Regardless, I am hoping to find a better solution than applying sleep to alter the order.

Hello Alexander,

I agree with you that this indeed seems to be a parallel execution issue. I also believe it could be similar in certain cases regarding data loading.

While I don’t have a solid argument to back this up, I have another suggestion that might help.

Would it be possible for you to create an action that handle all the “Subscribe to update” states that you need to modify in your app? If so, you could consolidate it into a single action and trigger it during any “On Load” event. This would ensure that you always have the data with the state that you need.

Peace !

1 Like

I agree that turning off “Subscribe to updates” on all data sources at each “On Load” would work nicely. Thanks for a better solution! Still, I can’t shake the feeling that turning off “Subscribe to updates” indiscriminately at every “On Load” is not ideal.

It is not undeed.

You can push it further by using conditions on the parameters to specifically pinpoint which data should have the “subscribe to update” feature. This way, you’ll have all the control in one single action, ensuring you don’t lose track of it.

Hopefully, this will be fixed soon.

Sorry I couldn’t offer more help than this.

2 Likes