Skip to content

Commit

Permalink
Simplify initial sync
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 17, 2020
1 parent 6b1660c commit db5f28c
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions panel/io/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,7 @@ def _update_synced(self, event=None):
def _update_query(self, *events, query=None):
if self._syncing:
return
serialized = {}
for k, v in (query or {}).items():
matches = [(o, ps) for o, ps, _ in self._synced if k in list(ps.values())]
if not matches:
continue
owner, ps = matches[0]
reverse = {p: r for r, p in ps.items()}
try:
v = owner.param[reverse[k]].serialize(v)
except Exception:
pass
serialized[k] = v
serialized = query or {}
for e in events:
matches = [ps for o, ps, _ in self._synced if o in (e.cls, e.obj)]
if not matches:
Expand Down Expand Up @@ -161,8 +150,17 @@ def sync(self, parameterized, parameters=None):
watcher = parameterized.param.watch(self._update_query, list(parameters))
self._synced.append((parameterized, parameters, watcher))
self._update_synced()
self._update_query(query={v: getattr(parameterized, k)
for k, v in parameters.items()})
query = {}
for p, name in parameters.items():
v = getattr(parameterized, p)
try:
parameterized.param[p].serialize(v)
except Exception:
pass
if not isinstance(v, str):
v = json.dumps(v)
query[name] = v
self._update_query(query=query)

def unsync(self, parameterized, parameters=None):
"""
Expand Down

0 comments on commit db5f28c

Please sign in to comment.