@@ -510,33 +510,15 @@ def send_state(self, key=None):
510
510
A single property's name or iterable of property names to sync with the front-end.
511
511
"""
512
512
state = self .get_state (key = key )
513
- if len (state ) == 0 :
514
- return
513
+ if len (state ) > 0 :
514
+ if self ._property_lock : # we need to keep this dict up to date with the front-end values
515
+ for name , value in state .items ():
516
+ if name in self ._property_lock :
517
+ self ._property_lock [name ] = value
518
+ state , buffer_paths , buffers = _remove_buffers (state )
519
+ msg = {'method' : 'update' , 'state' : state , 'buffer_paths' : buffer_paths }
520
+ self ._send (msg , buffers = buffers )
515
521
516
- # For any values that are currently locked (i.e., we are not echoing,
517
- # and we are currently processing an update for), we need to update our
518
- # notion of what the frontend value is.
519
-
520
- # TODO: does this handle the case where we get an update from the
521
- # frontend, in the middle of this we update the value *and send it*, and
522
- # then at the end we have to evaluate whether to send an echo message.
523
- # We need to send an echo message at some point so the originator can unblock
524
- # other echo messages, and we don't want to send the same data twice. So probably
525
- # the first time we send an update for an attribute back, we need to send it as an
526
- # echo, and record that we've already sent it. So perhaps we just need to keep
527
- # track of what echos we need to send, and we send at the end whatever echos still
528
- # need to be sent.
529
-
530
- # Sending echos at the end may send updates out of order, i.e., we may send
531
- # some updates in the middle, then send echos at the end. perhaps we should immediately
532
- # send echos just as we start processing the message?
533
- if self ._property_lock :
534
- for name , value in state .items ():
535
- if name in self ._property_lock :
536
- self ._property_lock [name ] = value
537
- state , buffer_paths , buffers = _remove_buffers (state )
538
- msg = {'method' : 'update' , 'state' : state , 'buffer_paths' : buffer_paths }
539
- self ._send (msg , buffers = buffers )
540
522
541
523
def get_state (self , key = None , drop_defaults = False ):
542
524
"""Gets the widget state, or a piece of it.
@@ -664,7 +646,9 @@ def __repr__(self):
664
646
@contextmanager
665
647
def _lock_property (self , ** properties ):
666
648
"""Lock a property-value pair.
649
+
667
650
The value should be the JSON state of the property.
651
+
668
652
NOTE: This, in addition to the single lock for all state changes, is
669
653
flawed. In the future we may want to look into buffering state changes
670
654
back to the front-end."""
0 commit comments