From f5a4232e4b3d779447f4390c35c5480fe2c682e7 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Sat, 20 Jun 2020 22:56:23 +0200 Subject: [PATCH] Ensure param callbacks initialized (#1439) * Implement Param.select * Implement Param.select to ensure JS callbacks are processed --- panel/param.py | 17 +++++++++++++++++ panel/tests/test_param.py | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/panel/param.py b/panel/param.py index a32dce5005..d12273423d 100644 --- a/panel/param.py +++ b/panel/param.py @@ -532,6 +532,23 @@ def widget_type(cls, pobj): return cls._mapping[t](pobj) return cls._mapping[t] + def select(self, selector=None): + """ + Iterates over the Viewable and any potential children in the + applying the Selector. + + Arguments + --------- + selector: type or callable or None + The selector allows selecting a subset of Viewables by + declaring a type or callable function to filter by. + + Returns + ------- + viewables: list(Viewable) + """ + return super().select(selector) + self.layout.select(selector) + def get_root(self, doc=None, comm=None): """ Returns the root model and applies pre-processing hooks diff --git a/panel/tests/test_param.py b/panel/tests/test_param.py index dd531f631b..e647c7571a 100644 --- a/panel/tests/test_param.py +++ b/panel/tests/test_param.py @@ -832,6 +832,24 @@ class Test(param.Parameterized): assert len(model.tabs) == 1 +def test_param_js_callbacks(document, comm): + class JsButton(param.Parameterized): + param_btn = param.Action(lambda self: print('Action Python Response'), label='Action') + + param_button = Param(JsButton()) + code = "console.log('Action button clicked')" + param_button[1].js_on_click(code=code) + + model = param_button.get_root(document, comm=comm) + + button = model.children[1] + assert len(button.js_event_callbacks) == 1 + callbacks = button.js_event_callbacks + assert 'button_click' in callbacks + assert len(callbacks['button_click']) == 1 + assert code in callbacks['button_click'][0].code + + class View(param.Parameterized): a = param.Integer(default=0)