Show More
@@ -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. |
|
|
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