Skip to content

Commit

Permalink
Clean up after some self-review
Browse files Browse the repository at this point in the history
  • Loading branch information
mofojed committed Nov 21, 2023
1 parent b24251d commit 1f486b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions plugins/ui/src/deephaven/ui/object_types/ElementMessageStream.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import annotations
import json
import io
from jsonrpc import JSONRPCResponseManager, Dispatcher
import logging
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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)
4 changes: 2 additions & 2 deletions plugins/ui/src/deephaven/ui/renderer/NodeEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
):
Expand Down

0 comments on commit 1f486b7

Please sign in to comment.