deephaven / deephaven-plugins

Deephaven Plugins
5 stars 12 forks source link

feat: Return callables from callables in Deephaven UI #540

Closed mattrunyon closed 3 weeks ago

mattrunyon commented 1 month ago

Fixes #322. Will be required for full completion of #321.

Currently a little hard to test, but this should demonstrate it if you watch the JS debug logs on WidgetHandler.

Run this Python code.

from deephaven import ui

@ui.component
def my_comp():
    on_press = ui.use_callback(lambda d: print(d), [])
    on_press_nested = ui.use_callback(lambda: print, [])
    on_press_double_nested = ui.use_callback(lambda: { "nestedFn": print, "some_val": 4 }, [])
    on_press_unserializable = ui.use_callback(lambda: set([1, 2, 3]), [])
    return [
        ui.button("Normal", on_press=on_press),
        ui.button("Nested", on_press=on_press_nested),
        ui.button("Double Nested", on_press=on_press_double_nested),
        ui.button("Not Serializable", on_press=on_press_unserializable)
    ]

c = my_comp()