diff --git a/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py b/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py index 1d052c2c3..2cd23cc07 100644 --- a/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py +++ b/plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py @@ -1,5 +1,4 @@ from __future__ import annotations -import json import io from jsonrpc import JSONRPCResponseManager, Dispatcher import logging @@ -28,6 +27,7 @@ def __init__(self, element: Element, connection: MessageStream): self._message_id = 0 self._manager = JSONRPCResponseManager() self._dispatcher = Dispatcher() + self._encoder = NodeEncoder(separators=(",", ":")) def start(self) -> None: context = RenderContext() @@ -61,7 +61,7 @@ def _get_next_message_id(self) -> int: self._message_id += 1 return self._message_id - def _make_notification(self, method: str, *params: list[Any]) -> None: + def _make_notification(self, method: str, *params: Any) -> dict[str, Any]: """ Make a JSON-RPC notification. Can notify the client without expecting a response. @@ -75,7 +75,7 @@ def _make_notification(self, method: str, *params: list[Any]) -> None: "params": params, } - def _make_request(self, method: str, *params: list[Any]) -> None: + def _make_request(self, method: str, *params: Any) -> dict[str, Any]: """ Make a JSON-RPC request. Messages the client and expects a response. @@ -97,16 +97,16 @@ def _send_document_update(self, root: RenderedNode) -> None: Args: root: The root node of the document to send """ + # TODO(#67): Send a diff of the document instead of the entire document. request = self._make_notification("documentUpdated", root) - encoder = NodeEncoder(separators=(",", ":")) - payload = encoder.encode(request) + payload = self._encoder.encode(request) logger.debug(f"Sending payload: {payload}") dispatcher = Dispatcher() - for cb, callable_id in encoder.callable_dict.items(): + for callable, callable_id in self._encoder.callable_dict.items(): logger.debug("Registering callable %s", callable_id) - dispatcher[callable_id] = cb + dispatcher[callable_id] = callable self._dispatcher = dispatcher - self._connection.on_data(payload.encode(), encoder.new_objects) + self._connection.on_data(payload.encode(), self._encoder.new_objects) diff --git a/plugins/ui/src/deephaven/ui/renderer/NodeEncoder.py b/plugins/ui/src/deephaven/ui/renderer/NodeEncoder.py index 50cb10e8b..acdb12632 100644 --- a/plugins/ui/src/deephaven/ui/renderer/NodeEncoder.py +++ b/plugins/ui/src/deephaven/ui/renderer/NodeEncoder.py @@ -9,7 +9,7 @@ OBJECT_KEY = "__dhObid" ELEMENT_KEY = "__dhElemName" -DEFALT_CALLABLE_ID_PREFIX = "cb" +DEFAULT_CALLABLE_ID_PREFIX = "cb" # IDs for callables are prefixes with a string and then use the `id` of the callable itself CallableId = str @@ -53,7 +53,7 @@ class NodeEncoder(json.JSONEncoder): def __init__( self, - callable_id_prefix: str = DEFALT_CALLABLE_ID_PREFIX, + callable_id_prefix: str = DEFAULT_CALLABLE_ID_PREFIX, *args: Any, **kwargs: Any, ):