Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
12.61k stars 951 forks source link

Make Taipy GUI search and run local on_init(state) functions #1341

Open cheak1974 opened 4 months ago

cheak1974 commented 4 months ago

Description

At the time Taipy is just searching and running the global on_init(state) function which is not very handy, because you have to manually import and call an local on_init function in the local page code.

Furthermore the code is only run once and gets the state id "global". So when Taipy starts the on_init function is called once and it makes absolutely no sense to forward the state object to the call of the local on_init function like mentioned in the docs, because it isn't the state of the new user session/connection but stays always the global state.

Solution Proposed

I would propose to call a function on_init(state) in each local module which would give the user the possibility to start e.g. data aquisition threads when a new connection opens up. Very useful could also be a standard variable bound to the state object to query if the connection is still alive. This would be great for ending such data aquisition threads when the user disconnects.

Impact of Solution

none

Additional Context

none

Acceptance Criteria

Code of Conduct

FlorianJacta commented 4 months ago

How is it not called for each new state? It should. Otherwise, I like the idea but I am not sure how to decide which on_init should be called first if you have multiple ones. It should create some issues

FredLL-Avaiga commented 3 months ago

Would you care to share some reproduction code for the global state issue?

FabienLelaquais commented 1 month ago

Isn't this issue covered by Page Modules?