Skip to content

Commit

Permalink
removed coordinate conversion, implemented a "_has_click_handlers" tr…
Browse files Browse the repository at this point in the history
…ait for the front end to use so unnecessary messages arent sent if there are no python callbacks registered, and flip floppped the guard clause on the _handle_anywidget_dispatch
  • Loading branch information
ATL2001 committed Oct 24, 2024
1 parent e781f95 commit 052413b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
10 changes: 7 additions & 3 deletions lonboard/_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ def __init__(
def _handle_anywidget_dispatch(
widget: ipywidgets.Widget, msg: Union[str, list, dict], buffers: List[bytes]
) -> None:
if msg.get("kind") != "on-click":
return
self._click_handlers(tuple(msg.get("coordinate")))
if msg.get("kind") == "on-click":
self._click_handlers(tuple(msg.get("coordinate")))

super().__init__(layers=layers, **kwargs)
self._click_handlers = CallbackDispatcher()
Expand All @@ -124,6 +123,7 @@ def on_click(self, callback, remove=False):
Set to true to remove the callback from the list of callbacks.
"""
self._click_handlers.register_callback(callback, remove=remove)
self._has_click_handlers = len(self._click_handlers.callbacks) > 0

_esm = bundler_output_dir / "index.js"
_css = bundler_output_dir / "index.css"
Expand Down Expand Up @@ -151,6 +151,10 @@ def on_click(self, callback, remove=False):
once it's been initially rendered.
"""
_has_click_handlers = t.Bool(default_value=False, allow_none=False).tag(sync=True)
"""
Indicates if a click handler has been registered.
"""

_height = t.Int(default_value=DEFAULT_HEIGHT, allow_none=True).tag(sync=True)
"""Height of the map in pixels.
Expand Down
18 changes: 10 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,17 @@ function App() {
// We added this flag to prevent the hover event from firing after a
// click event.
if (typeof info.coordinate !== "undefined") {
let x = info.coordinate[0];
while (x < 180) {
x += 360;
// let x = info.coordinate[0];
// while (x < 180) {
// x += 360;
// }
// while (x > 180) {
// x -= 360;
// }
// info.coordinate[0] = x;
if (model.get("_has_click_handlers")) {
model.send({ kind: "on-click", coordinate: info.coordinate });
}
while (x > 180) {
x -= 360;
}
info.coordinate[0] = x;
model.send({ kind: "on-click", coordinate: info.coordinate });
}
setJustClicked(true);
actorRef.send({
Expand Down

0 comments on commit 052413b

Please sign in to comment.