@@ -68,11 +68,6 @@ def __init__(
6868 self .web_modules_dir = config .REACTPY_WEB_MODULES_DIR .current
6969 self .static_dir = Path (__file__ ).parent .parent / "static"
7070
71- # Sub-applications
72- self .component_dispatch_app = ComponentDispatchApp (parent = self )
73- self .static_file_app = StaticFileApp (parent = self )
74- self .web_modules_app = WebModuleApp (parent = self )
75-
7671 # Validate the configuration
7772 reason = check_path (self .path_prefix )
7873 if reason :
@@ -82,6 +77,11 @@ def __init__(
8277 f"Web modules directory { self .web_modules_dir } does not exist."
8378 )
8479
80+ # Initialize the sub-applications
81+ self .component_dispatch_app = ComponentDispatchApp (parent = self )
82+ self .static_file_app = StaticFileApp (parent = self )
83+ self .web_modules_app = WebModuleApp (parent = self )
84+
8585 async def __call__ (
8686 self ,
8787 scope : dict [str , Any ],
@@ -188,23 +188,16 @@ async def run_dispatcher(
188188 # Start the ReactPy component rendering loop
189189 await serve_layout (
190190 Layout (ConnectionContext (component (), value = connection )), # type: ignore
191- self ._send_json (send ),
191+ lambda msg : send (
192+ {"type" : "websocket.send" , "text" : orjson .dumps (msg ).decode ()}
193+ ),
192194 recv_queue .get ,
193195 )
194196
195197 # Manually log exceptions since this function is running in a separate asyncio task.
196198 except Exception as error :
197199 await asyncio .to_thread (_logger .error , f"{ error } \n { traceback .format_exc ()} " )
198200
199- @staticmethod
200- def _send_json (send : Callable ) -> Callable [..., Coroutine ]:
201- """Use orjson to send JSON over an ASGI websocket."""
202-
203- async def _send (value : Any ) -> None :
204- await send ({"type" : "websocket.send" , "text" : orjson .dumps (value ).decode ()})
205-
206- return _send
207-
208201
209202@dataclass
210203class StaticFileApp :
0 commit comments