Skip to content

Commit

Permalink
Ensure param callbacks initialized (#1439)
Browse files Browse the repository at this point in the history
* Implement Param.select

* Implement Param.select to ensure JS callbacks are processed
  • Loading branch information
philippjfr authored Jun 20, 2020
1 parent b258bd0 commit 383f306
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions panel/tests/test_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 383f306

Please sign in to comment.