Skip to content

Commit

Permalink
fix: vue component with default event handler values were serializated
Browse files Browse the repository at this point in the history
The default event handler values were attempted to serialized since
they were added as a trait with a default value. This was causing
the serialization to fail since the default value was not a valid
JSON (it is a Python function)
  • Loading branch information
maartenbreddels committed Mar 28, 2024
1 parent d951de2 commit 793cbb1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions solara/components/component_vue.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ def _widget_from_signature(classname, base_class: Type[widgets.Widget], func: Ca
if name.startswith("event_"):
event_name = name[6:]

def event_handler(self, data, buffers=None, event_name=event_name):
callback = self._event_callbacks.get(event_name)
def event_handler(self, data, buffers=None, event_name=event_name, param=param):
callback = self._event_callbacks.get(event_name, param.default)
if callback:
if buffers:
callback(data, buffers)
else:
callback(data)

classprops[f"vue_{event_name}"] = event_handler
if name.startswith("on_") and name[3:] in parameters:
elif name.startswith("on_") and name[3:] in parameters:
# callback, will be handled by reacton
continue
if param.default == inspect.Parameter.empty:
trait = traitlets.Any()
else:
trait = traitlets.Any(default_value=param.default)
classprops[name] = trait.tag(sync=True, **widgets.widget_serialization)
if param.default == inspect.Parameter.empty:
trait = traitlets.Any()
else:
trait = traitlets.Any(default_value=param.default)
classprops[name] = trait.tag(sync=True, **widgets.widget_serialization)
# maps event_foo to a callable
classprops["_event_callbacks"] = traitlets.Dict(default_value={})

Expand Down

0 comments on commit 793cbb1

Please sign in to comment.