Skip to content

Commit

Permalink
Updated Viewable.jslink and jscallback
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 27, 2019
1 parent 9200290 commit 6395bf5
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions panel/viewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,27 +826,30 @@ def add_periodic_callback(self, callback, period=500, count=None,

def jscallback(self, args={}, **callbacks):
"""
Allows defining a JS callback to be triggered when a property
changes on the source object. The keyword arguments define the
properties that trigger a callback and the JS code that gets
executed.
Arguments
----------
target: HoloViews object or bokeh Model or panel Viewable
The target to link the value to.
args: A mapping of objects to make available to the JS callback
**callbacks: dict
A mapping between properties on the source model and the code
to execute when that property changes
Returns
-------
link: GenericCallback
The GenericCallback which can be used to disable the callback.
callback: Callback
The Callback which can be used to disable the callback.
"""

from .links import GenericCallback
from .links import Callback
for k, v in list(callbacks.items()):
callbacks[k] = self._rename.get(v, v)
return GenericCallback(self, code=callbacks, args=args)
return Callback(self, code=callbacks, args=args)

def jslink(self, target, code=None, **links):
def jslink(self, target, code=None, args=None, **links):
"""
Links properties on the source object to those on the target
object in JS code. Supports two modes, either specify a
Expand Down Expand Up @@ -879,10 +882,12 @@ def jslink(self, target, code=None, **links):
elif not links and not code:
raise ValueError('Declare parameters to link or a set of '
'callbacks, neither was defined.')
if args is None:
args = {}

from .links import GenericLink
from .links import Link
if isinstance(target, Reactive):
mapping = code or links
for k, v in list(mapping.items()):
mapping[k] = target._rename.get(v, v)
return GenericLink(self, target, properties=links, code=code)
return Link(self, target, properties=links, code=code, args=args)

0 comments on commit 6395bf5

Please sign in to comment.