Skip to content

Commit

Permalink
Fixed applying of modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jul 23, 2020
1 parent d99179d commit 5b7ad80
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions panel/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,18 @@ def __repr__(self):
return template.format(
cls=cls, objs=('%s' % spacer).join(objs), spacer=spacer)

def _apply_modifiers(self, viewable, mref):
@classmethod
def _apply_hooks(cls, viewable, root):
ref = root.ref['id']
for o in viewable.select():
cls._apply_modifiers(o, ref)

@classmethod
def _apply_modifiers(cls, viewable, mref):
if mref not in viewable._models:
return
model, _ = viewable._models[mref]
modifiers = self._modifiers.get(type(viewable), {})
modifiers = cls._modifiers.get(type(viewable), {})
child_modifiers = modifiers.get('children', {})
if child_modifiers:
for child in viewable:
Expand All @@ -99,11 +106,15 @@ def _apply_modifiers(self, viewable, mref):
if getattr(child, k) == child.param[k].default
}
child.param.set_param(**child_params)
child_props = child._process_param_change(child_params)
child._models[mref][0].update(**child_props)
params = {
k: v for k, v in modifiers.items() if k != 'children' and
getattr(viewable, k) == viewable.param[k].default
}
viewable.param.set_param(**params)
props = viewable._process_param_change(params)
model.update(**props)

def _apply_root(self, name, viewable, tags):
pass
Expand All @@ -116,6 +127,8 @@ def _init_doc(self, doc=None, comm=None, title=None, notebook=False, location=Tr
preprocess_root = col.get_root(doc, comm)
ref = preprocess_root.ref['id']
for name, (obj, tags) in self._render_items.items():
if self._apply_hooks not in obj._hooks:
obj._hooks.append(self._apply_hooks)
model = obj.get_root(doc, comm)
mref = model.ref['id']
doc.on_session_destroyed(obj._server_destroy)
Expand All @@ -131,8 +144,6 @@ def _init_doc(self, doc=None, comm=None, title=None, notebook=False, location=Tr
model.name = name
model.tags = tags
self._apply_root(name, model, tags)
for o in obj.select():
self._apply_modifiers(o, mref)
add_to_doc(model, doc, hold=bool(comm))

state._fake_roots.append(ref)
Expand Down Expand Up @@ -358,7 +369,7 @@ def __init__(self, **params):
self.header.param.watch(self._update_render_items, ['objects'])
self.param.watch(self._update_vars, ['title', 'header_background',
'header_color'])
self._callbacks = {'main': [], 'sidebar': [], 'header': [], 'modal': []}
self._callbacks = {'main': [], 'nav': [], 'header': [], 'modal': []}
self._js_area = HTML(margin=0, width=0, height=0)

@property
Expand Down

0 comments on commit 5b7ad80

Please sign in to comment.