##// END OF EJS Templates
Merge pull request #6582 from jdfreder/symmetric_state...
Matthias Bussonnier -
r18113:af828fe4 merge
parent child Browse files
Show More
@@ -69,7 +69,7 b' define(["widgets/js/manager",'
69 69 var method = msg.content.data.method;
70 70 switch (method) {
71 71 case 'update':
72 this.apply_update(msg.content.data.state);
72 this.set_state(msg.content.data.state);
73 73 break;
74 74 case 'custom':
75 75 this.trigger('msg:custom', msg.content.data.content);
@@ -80,7 +80,7 b' define(["widgets/js/manager",'
80 80 }
81 81 },
82 82
83 apply_update: function (state) {
83 set_state: function (state) {
84 84 // Handle when a widget is updated via the python side.
85 85 this.state_lock = state;
86 86 try {
@@ -118,8 +118,8 b' casper.notebook_test(function () {'
118 118 ' b = CInt(0, sync=True)\n' +
119 119 ' c = CInt(0, sync=True)\n' +
120 120 ' d = CInt(-1, sync=True)\n' + // See if it sends a full state.
121 ' def _handle_receive_state(self, sync_data):\n' +
122 ' widgets.Widget._handle_receive_state(self, sync_data)\n'+
121 ' def set_state(self, sync_data):\n' +
122 ' widgets.Widget.set_state(self, sync_data)\n'+
123 123 ' self.d = len(sync_data)\n' +
124 124 'multiset = MultiSetWidget()\n' +
125 125 'display(multiset)\n' +
@@ -209,6 +209,15 b' class Widget(LoggingConfigurable):'
209 209 state[k] = f(value)
210 210 return state
211 211
212 def set_state(self, sync_data):
213 """Called when a state is received from the front-end."""
214 for name in self.keys:
215 if name in sync_data:
216 json_value = sync_data[name]
217 from_json = self.trait_metadata(name, 'from_json', self._trait_from_json)
218 with self._lock_property(name, json_value):
219 setattr(self, name, from_json(json_value))
220
212 221 def send(self, content):
213 222 """Sends a custom msg to the widget model in the front-end.
214 223
@@ -304,22 +313,13 b' class Widget(LoggingConfigurable):'
304 313 # Handle backbone sync methods CREATE, PATCH, and UPDATE all in one.
305 314 if method == 'backbone' and 'sync_data' in data:
306 315 sync_data = data['sync_data']
307 self._handle_receive_state(sync_data) # handles all methods
316 self.set_state(sync_data) # handles all methods
308 317
309 318 # Handle a custom msg from the front-end
310 319 elif method == 'custom':
311 320 if 'content' in data:
312 321 self._handle_custom_msg(data['content'])
313 322
314 def _handle_receive_state(self, sync_data):
315 """Called when a state is received from the front-end."""
316 for name in self.keys:
317 if name in sync_data:
318 json_value = sync_data[name]
319 from_json = self.trait_metadata(name, 'from_json', self._trait_from_json)
320 with self._lock_property(name, json_value):
321 setattr(self, name, from_json(json_value))
322
323 323 def _handle_custom_msg(self, content):
324 324 """Called when a custom msg is received."""
325 325 self._msg_callbacks(self, content)
General Comments 0
You need to be logged in to leave comments. Login now