38
38
from idom .backend .hooks import ConnectionContext
39
39
from idom .backend .hooks import use_connection as _use_connection
40
40
from idom .backend .types import Connection , Location
41
- from idom .core .layout import LayoutEvent , LayoutUpdate
42
- from idom .core .serve import serve_json_patch
41
+ from idom .core .serve import serve_layout
43
42
from idom .core .types import ComponentType , RootComponentConstructor
44
43
from idom .utils import Ref
45
44
@@ -182,8 +181,8 @@ def model_stream(ws: WebSocket, path: str = "") -> None:
182
181
def send (value : Any ) -> None :
183
182
ws .send (json .dumps (value ))
184
183
185
- def recv () -> LayoutEvent :
186
- return LayoutEvent ( ** json .loads (ws .receive () ))
184
+ def recv () -> Any :
185
+ return json .loads (ws .receive ())
187
186
188
187
_dispatch_in_thread (
189
188
ws ,
@@ -203,7 +202,7 @@ def _dispatch_in_thread(
203
202
path : str ,
204
203
component : ComponentType ,
205
204
send : Callable [[Any ], None ],
206
- recv : Callable [[], Optional [LayoutEvent ]],
205
+ recv : Callable [[], Optional [Any ]],
207
206
) -> NoReturn :
208
207
dispatch_thread_info_created = ThreadEvent ()
209
208
dispatch_thread_info_ref : idom .Ref [Optional [_DispatcherThreadInfo ]] = idom .Ref (None )
@@ -213,18 +212,15 @@ def run_dispatcher() -> None:
213
212
loop = asyncio .new_event_loop ()
214
213
asyncio .set_event_loop (loop )
215
214
216
- thread_send_queue : "ThreadQueue[LayoutUpdate ]" = ThreadQueue ()
217
- async_recv_queue : "AsyncQueue[LayoutEvent ]" = AsyncQueue ()
215
+ thread_send_queue : "ThreadQueue[Any ]" = ThreadQueue ()
216
+ async_recv_queue : "AsyncQueue[Any ]" = AsyncQueue ()
218
217
219
218
async def send_coro (value : Any ) -> None :
220
219
thread_send_queue .put (value )
221
220
222
- async def recv_coro () -> Any :
223
- return await async_recv_queue .get ()
224
-
225
221
async def main () -> None :
226
222
search = request .query_string .decode ()
227
- await serve_json_patch (
223
+ await serve_layout (
228
224
idom .Layout (
229
225
ConnectionContext (
230
226
component ,
@@ -239,7 +235,7 @@ async def main() -> None:
239
235
),
240
236
),
241
237
send_coro ,
242
- recv_coro ,
238
+ async_recv_queue . get ,
243
239
)
244
240
245
241
main_future = asyncio .ensure_future (main (), loop = loop )
@@ -282,9 +278,9 @@ def run_send() -> None:
282
278
283
279
class _DispatcherThreadInfo (NamedTuple ):
284
280
dispatch_loop : asyncio .AbstractEventLoop
285
- dispatch_future : " asyncio.Future[Any]"
286
- thread_send_queue : " ThreadQueue[LayoutUpdate]"
287
- async_recv_queue : " AsyncQueue[LayoutEvent]"
281
+ dispatch_future : asyncio .Future [Any ]
282
+ thread_send_queue : ThreadQueue [Any ]
283
+ async_recv_queue : AsyncQueue [Any ]
288
284
289
285
290
286
@dataclass
0 commit comments