Skip to content

Commit

Permalink
refactor: Remove use of anywidget-command kind
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Jul 21, 2024
1 parent 38582ee commit 9600f14
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion localtileserver/custom/lts_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function render({ model, el, experimental }) {
tileHandlers[id] = handleTile;

model.send(
{ id, kind: "anywidget-command", name: "get_tile", msg: {...coords, identifier} },
{ id, kind: "get_tile", msg: {...coords, identifier} },
undefined,
[],
);
Expand Down
10 changes: 4 additions & 6 deletions localtileserver/custom/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
THREAD_EXECUTOR = concurrent.futures.ThreadPoolExecutor(max_workers=os.cpu_count())


def handle_anywidget_command(widget, msg: str | list | dict, buffers: list[bytes]) -> None:
if not isinstance(msg, dict) or msg.get("kind") != "anywidget-command":
return
def handle_custom_message(widget, msg: dict, buffers: list[bytes]) -> None:
assert msg["kind"] == "get_tile", f"unexpected message kind: {msg['kind']}"

def target():
response, buffers = widget.get_tile(msg["msg"])
widget.send(
{
"id": msg["id"],
"kind": "anywidget-command-response",
"response": response,
},
buffers,
Expand All @@ -36,7 +34,7 @@ class TileLayerWidget(anywidget.AnyWidget):
"""Leaflet Tile Layer Widget.
Args:
anywidget (_type_): _description_
client (TileClient): A TileClient instance.
"""

_esm = THIS_DIR / "lts_widget.js"
Expand All @@ -50,7 +48,7 @@ class TileLayerWidget(anywidget.AnyWidget):
def __init__(self, client: TileClient, **kwargs):
super().__init__()
self.client = client # TODO: weakref?
self.on_msg(handle_anywidget_command)
self.on_msg(handle_custom_message)
self._display_kwargs = kwargs
self.bounds = self.client.bounds()
self.identifier = uuid.uuid4().hex
Expand Down

0 comments on commit 9600f14

Please sign in to comment.