Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhlongviolin1 committed Oct 18, 2023
1 parent 924454a commit edd10e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
29 changes: 14 additions & 15 deletions src/taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ class Gui:
__UI_BLOCK_NAME = "TaipyUiBlockVar"
__MESSAGE_GROUPING_NAME = "TaipyMessageGrouping"
__ON_INIT_NAME = "TaipyOnInit"
__ON_LIB_INIT_NAME = "TaipyOnLibsInit"
__ARG_CLIENT_ID = "client_id"
__INIT_URL = "taipy-init"
__JSX_URL = "taipy-jsx"
Expand Down Expand Up @@ -1709,24 +1708,23 @@ def _navigate(
return True

def __init_libs(self):
if not _hasscopeattr(self, Gui.__ON_LIB_INIT_NAME):
_setscopeattr(self, Gui.__ON_LIB_INIT_NAME, True)
for name, libs in self.__extensions.items():
for lib in libs:
if not isinstance(lib, ElementLibrary):
continue
try:
self._call_function_with_state(lib.on_user_init, [])
except Exception as e: # pragma: no cover
if not self._call_on_exception(f"{name}.on_user_init", e):
_warn(f"Exception raised in {name}.on_user_init()", e)
for name, libs in self.__extensions.items():
for lib in libs:
if not isinstance(lib, ElementLibrary):
continue
try:
self._call_function_with_state(lib.on_user_init, [])
except Exception as e: # pragma: no cover
if not self._call_on_exception(f"{name}.on_user_init", e):
_warn(f"Exception raised in {name}.on_user_init()", e)

def __init_route(self):
self.__set_client_id_in_context()
self.__init_libs()
if not _hasscopeattr(self, Gui.__ON_INIT_NAME):
_setscopeattr(self, Gui.__ON_INIT_NAME, True)
self.__pre_render_pages()
self.__init_libs()
if hasattr(self, "on_init") and callable(self.on_init):
_setscopeattr(self, Gui.__ON_INIT_NAME, True)
try:
self._call_function_with_state(self.on_init, [])
except Exception as e: # pragma: no cover
Expand All @@ -1752,7 +1750,8 @@ def __call_on_status(self) -> t.Optional[str]:
_warn("Exception raised in on_status", e)
return None

def _pre_render_pages(self) -> None:
def __pre_render_pages(self) -> None:
"""Pre-render all pages to have a proper initialization of all variables"""
self.__set_client_id_in_context()
for page in self._config.pages:
if page is not None:
Expand Down
6 changes: 0 additions & 6 deletions src/taipy/gui/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def change_variable(state):
"broadcast",
"get_gui",
"refresh",
"pre_render_pages",
"_set_context",
"_reset_context",
"_get_placeholder",
Expand Down Expand Up @@ -261,11 +260,6 @@ def broadcast(self, name: str, value: t.Any):
gui._broadcast_all_clients(encoded_name, value)
self._reset_context(gui, set_context)

def pre_render_pages(self):
"""Pre-render all pages to have a proper initialization of all variables"""
gui: "Gui" = super().__getattribute__(State.__gui_attr)
gui._pre_render_pages()

def __enter__(self):
super().__getattribute__(State.__attrs[0]).__enter__()
return self
Expand Down

0 comments on commit edd10e9

Please sign in to comment.