Prechádzať zdrojové kódy

extract lifecycle code

Falko Schindler 3 rokov pred
rodič
commit
65d9a20209
2 zmenil súbory, kde vykonal 14 pridanie a 14 odobranie
  1. 13 0
      nicegui/lifecycle.py
  2. 1 14
      nicegui/ui.py

+ 13 - 0
nicegui/lifecycle.py

@@ -0,0 +1,13 @@
+from typing import Awaitable, Callable, List, Union
+
+startup_tasks: List[Union[Callable, Awaitable]] = []
+
+def on_startup(self, task: Union[Callable, Awaitable]):
+
+    self.startup_tasks.append(task)
+
+shutdown_tasks: List[Union[Callable, Awaitable]] = []
+
+def on_shutdown(self, task: Union[Callable, Awaitable]):
+
+    self.shutdown_tasks.append(task)

+ 1 - 14
nicegui/ui.py

@@ -1,6 +1,3 @@
-from typing import Awaitable, Callable, List, Union
-
-
 class Ui:
 
     from .run import run, config  # NOTE: before justpy
@@ -33,14 +30,4 @@ class Ui:
 
     from .timer import Timer as timer
 
-    startup_tasks: List[Union[Callable, Awaitable]] = []
-
-    def on_startup(self, task: Union[Callable, Awaitable]):
-
-        self.startup_tasks.append(task)
-
-    shutdown_tasks: List[Union[Callable, Awaitable]] = []
-
-    def on_shutdown(self, task: Union[Callable, Awaitable]):
-
-        self.shutdown_tasks.append(task)
+    from .lifecycle import startup_tasks, on_startup, shutdown_tasks, on_shutdown