##// END OF EJS Templates
Make the widget property_lock store the JSON state, not the original object...
Jason Grout -
Show More
@@ -202,9 +202,7 b' class Widget(LoggingConfigurable):'
202 202 raise ValueError("key must be a string, an iterable of keys, or None")
203 203 state = {}
204 204 for k in keys:
205 f = self.trait_metadata(k, 'to_json')
206 if f is None:
207 f = self._trait_to_json
205 f = self.trait_metadata(k, 'to_json', self._trait_to_json)
208 206 value = getattr(self, k)
209 207 state[k] = f(value)
210 208 return state
@@ -255,6 +253,8 b' class Widget(LoggingConfigurable):'
255 253 def _lock_property(self, key, value):
256 254 """Lock a property-value pair.
257 255
256 The value should be the JSON state of the property.
257
258 258 NOTE: This, in addition to the single lock for all state changes, is
259 259 flawed. In the future we may want to look into buffering state changes
260 260 back to the front-end."""
@@ -280,7 +280,9 b' class Widget(LoggingConfigurable):'
280 280
281 281 def _should_send_property(self, key, value):
282 282 """Check the property lock (property_lock)"""
283 if (key == self._property_lock[0] and value == self._property_lock[1]):
283 to_json = self.trait_metadata(key, 'to_json', self._trait_to_json)
284 if (key == self._property_lock[0]
285 and to_json(value) == self._property_lock[1]):
284 286 return False
285 287 elif self._send_state_lock > 0:
286 288 self._states_to_send.add(key)
@@ -311,12 +313,10 b' class Widget(LoggingConfigurable):'
311 313 """Called when a state is received from the front-end."""
312 314 for name in self.keys:
313 315 if name in sync_data:
314 f = self.trait_metadata(name, 'from_json')
315 if f is None:
316 f = self._trait_from_json
317 value = f(sync_data[name])
318 with self._lock_property(name, value):
319 setattr(self, name, value)
316 json_value = sync_data[name]
317 from_json = self.trait_metadata(name, 'from_json', self._trait_from_json)
318 with self._lock_property(name, json_value):
319 setattr(self, name, from_json(json_value))
320 320
321 321 def _handle_custom_msg(self, content):
322 322 """Called when a custom msg is received."""
General Comments 0
You need to be logged in to leave comments. Login now