Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not process events related to fake Template root #1216

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions panel/io/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class _state(param.Parameterized):
# An index of all currently active views
_views = {}

# For templates to keep reference to their main root
_fake_roots = []

# An index of all currently active servers
_servers = {}

Expand Down
10 changes: 8 additions & 2 deletions panel/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from bokeh.models.widgets import Tabs as BkTabs, Panel as BkPanel

from .io.model import hold
from .io.state import state
from .util import param_name, param_reprs
from .viewable import Layoutable, Reactive

Expand Down Expand Up @@ -190,6 +191,8 @@ def _process_param_change(self, params):
return super(ListPanel, self)._process_param_change(params)

def _cleanup(self, root):
if root.ref['id'] in state._fake_roots:
state._fake_roots.remove(root.ref['id'])
super(ListPanel, self)._cleanup(root)
for p in self.objects:
p._cleanup(root)
Expand Down Expand Up @@ -652,14 +655,17 @@ def _process_close(self, ref, attr, old, new):
return old, new

def _comm_change(self, doc, ref, attr, old, new):
if attr in self._changing:
self._changing.remove(attr)
if attr in self._changing.get(ref, []):
self._changing[ref].remove(attr)
return
if attr == 'tabs':
old, new = self._process_close(ref, attr, old, new)
super(Tabs, self)._comm_change(doc, ref, attr, old, new)

def _server_change(self, doc, ref, attr, old, new):
if attr in self._changing.get(ref, []):
self._changing[ref].remove(attr)
return
if attr == 'tabs':
old, new = self._process_close(ref, attr, old, new)
super(Tabs, self)._server_change(doc, ref, attr, old, new)
Expand Down
2 changes: 2 additions & 0 deletions panel/pane/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def _update_object(self, ref, doc, root, parent, comm):

def _update_pane(self, *events):
for ref, (_, parent) in self._models.items():
if ref not in state._views or ref in state._fake_roots:
continue
viewable, root, doc, comm = state._views[ref]
if comm or state._unblocked(doc):
with unlocked():
Expand Down
1 change: 1 addition & 0 deletions panel/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def _init_doc(self, doc=None, comm=None, title=None, notebook=False):
model.name = name
model.tags = tags
add_to_doc(model, doc, hold=bool(comm))
state._fake_roots.append(ref)
state._views[ref] = (col, preprocess_root, doc, comm)

col._preprocess(preprocess_root)
Expand Down
16 changes: 8 additions & 8 deletions panel/viewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,16 @@ def _repr_mimebundle_(self, include=None, exclude=None):
return render_mimebundle(model, doc, comm, manager)

def _comm_change(self, doc, ref, attr, old, new):
if attr in self._changing:
self._changing.remove(attr)
if attr in self._changing.get(ref, []):
self._changing[ref].remove(attr)
return

with hold(doc):
self._process_events({attr: new})

def _server_change(self, doc, ref, attr, old, new):
if attr in self._changing:
self._changing.remove(attr)
if attr in self._changing.get(ref, []):
self._changing[ref].remove(attr)
return

state._locks.clear()
Expand Down Expand Up @@ -735,21 +735,21 @@ def __init__(self, **params):
self._callbacks = []
self._links = []
self._link_params()
self._changing = []
self._changing = {}

#----------------------------------------------------------------
# Callback API
#----------------------------------------------------------------

def _update_model(self, events, msg, root, model, doc, comm):
self._changing = [
self._changing[root.ref['id']] = [
attr for attr, value in msg.items()
if not model.lookup(attr).property.matches(getattr(model, attr), value)
]
try:
model.update(**msg)
finally:
self._changing = []
del self._changing[root.ref['id']]

def param_change(self, *events):
msgs = []
Expand All @@ -764,7 +764,7 @@ def param_change(self, *events):
return

for ref, (model, parent) in self._models.items():
if ref not in state._views:
if ref not in state._views or ref in state._fake_roots:
continue
viewable, root, doc, comm = state._views[ref]
if comm or not doc.session_context or state._unblocked(doc):
Expand Down
2 changes: 2 additions & 0 deletions panel/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def _manual_update(self, events, model, doc, root, parent, comm):

def _update_widget(self, *events):
for ref, (model, parent) in self._models.items():
if ref not in state._views or ref in state._fake_roots:
continue
viewable, root, doc, comm = state._views[ref]
if comm or state._unblocked(doc):
with unlocked():
Expand Down