Dispatch an event to the targeted handler
(self, event: LayoutEventMessage)
| 109 | del self._model_states_by_life_cycle_state_id |
| 110 | |
| 111 | async def deliver(self, event: LayoutEventMessage) -> None: |
| 112 | """Dispatch an event to the targeted handler""" |
| 113 | # It is possible for an element in the frontend to produce an event |
| 114 | # associated with a backend model that has been deleted. We only handle |
| 115 | # events if the element and the handler exist in the backend. Otherwise |
| 116 | # we just ignore the event. |
| 117 | handler = self._event_handlers.get(event["target"]) |
| 118 | |
| 119 | if handler is not None: |
| 120 | try: |
| 121 | await handler.function(event["data"]) |
| 122 | except Exception: |
| 123 | logger.exception(f"Failed to execute event handler {handler}") |
| 124 | else: |
| 125 | logger.info( |
| 126 | f"Ignored event - handler {event['target']!r} " |
| 127 | "does not exist or its component unmounted" |
| 128 | ) |
| 129 | |
| 130 | async def render(self) -> LayoutUpdateMessage: |
| 131 | if REACTPY_ASYNC_RENDERING.current: |