Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: detach on_msg handler on widget/template close #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ipyvue/VueTemplateWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def resolve_ref(value):
else:
getattr(self, "vue_" + event)(data)

def _clear_event_handler(self):
self.on_msg(self._handle_event, remove=True)


def _value_to_json(x, obj):
if inspect.isclass(x):
Expand Down Expand Up @@ -164,5 +167,9 @@ def on_ref_source_change(change):
for traitlet in sync_ref_traitlets:
create_ref_and_observe(traitlet)

def close(self):
self._clear_event_handler()
super().close()


__all__ = ["VueTemplate"]
7 changes: 7 additions & 0 deletions ipyvue/VueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def _handle_event(self, _, content, buffers):
data = content.get("data", {})
self._fire_event(event, data)

def _clear_event_handler(self):
self.on_msg(self._handle_event, remove=True)


class VueWidget(DOMWidget, Events):
# we can drop this when https://github.com/jupyter-widgets/ipywidgets/pull/3592
Expand Down Expand Up @@ -192,5 +195,9 @@ def hide(self):

self.class_list.add("d-none")

def close(self):
self._clear_event_handler()
super().close()


__all__ = ["VueWidget"]
Loading