Skip to content

Commit 6eff179

Browse files
committed
WIP simple reflection immediately on setting state.
1 parent 80ce43d commit 6eff179

File tree

1 file changed

+16
-10
lines changed
  • python/ipywidgets/ipywidgets/widgets

1 file changed

+16
-10
lines changed

python/ipywidgets/ipywidgets/widgets/widget.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -597,17 +597,23 @@ def _compare(self, a, b):
597597

598598
def set_state(self, sync_data):
599599
"""Called when a state is received from the front-end."""
600+
# Send an echo update message immediately
600601
if JUPYTER_WIDGETS_ECHO:
601-
with self._hold_sync_frontend(), self.hold_trait_notifications():
602-
# keep this as a list, not a set, since that preserves order (useful in the test)
603-
self._updated_attrs_from_frontend = [name for name in sync_data if name in self.keys]
604-
# TODO: this for-loop is the same as below. Only the context managers are different
605-
for name in sync_data:
606-
if name in self.keys:
607-
from_json = self.trait_metadata(name, 'from_json',
608-
self._trait_from_json)
609-
self.set_trait(name, from_json(sync_data[name], self))
610-
return
602+
echo_state = {}
603+
for attr,value in sync_data.items():
604+
if not self.trait_metadata(attr, 'no_echo'):
605+
echo_state[attr] = value
606+
if echo_state:
607+
echo_state, echo_buffer_paths, echo_buffers = _remove_buffers(echo_state)
608+
msg = {
609+
'method': 'update',
610+
'state': {},
611+
'buffer_paths': [],
612+
'echo_state': echo_state,
613+
'echo_buffer_paths': echo_buffer_paths
614+
}
615+
self._send(msg, buffers=echo_buffers)
616+
611617
# The order of these context managers is important. Properties must
612618
# be locked when the hold_trait_notification context manager is
613619
# released and notifications are fired.

0 commit comments

Comments
 (0)