fix for reactive vars not ready

This commit is contained in:
Will McGugan
2022-10-06 11:49:14 +01:00
parent ab40f75d60
commit 9bb5fc59d7
3 changed files with 4 additions and 2 deletions

View File

@@ -642,6 +642,7 @@ class App(Generic[ReturnType], DOMNode):
)
async def run_app() -> None:
if quit_after is not None:
self.set_timer(quit_after, self.shutdown)
if press is not None:
@@ -1100,6 +1101,7 @@ class App(Generic[ReturnType], DOMNode):
mount_event = events.Mount(sender=self)
await self._dispatch_message(mount_event)
Reactive.initialize_object(self)
self.title = self._title
self.stylesheet.update(self)
self.refresh()

View File

@@ -286,6 +286,7 @@ class MessagePump(metaclass=MessagePumpMeta):
def _start_messages(self) -> None:
"""Start messages task."""
Reactive.initialize_object(self)
self._task = asyncio.create_task(self._process_messages())
async def _process_messages(self) -> None:
@@ -303,7 +304,6 @@ class MessagePump(metaclass=MessagePumpMeta):
"""Process messages until the queue is closed."""
_rich_traceback_guard = True
await Reactive.initialize_object(self)
while not self._closed:
try:
message = await self._get_message()

View File

@@ -83,7 +83,7 @@ class Reactive(Generic[ReactiveType]):
return cls(default, layout=False, repaint=False, init=True)
@classmethod
async def initialize_object(cls, obj: object) -> None:
def initialize_object(cls, obj: object) -> None:
"""Call any watchers / computes for the first time.
Args: