From 8e1c52382c71dcea0186a26a752e4ee1f6564fff Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Tue, 3 Dec 2013 22:29:33 +0000 Subject: [PATCH] Added `method` property to messages from the front-end --- IPython/html/static/notebook/js/widget.js | 6 +++--- IPython/html/widgets/widget.py | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/IPython/html/static/notebook/js/widget.js b/IPython/html/static/notebook/js/widget.js index fe1fe11af..d903a00fc 100644 --- a/IPython/html/static/notebook/js/widget.js +++ b/IPython/html/static/notebook/js/widget.js @@ -78,7 +78,7 @@ define(["components/underscore/underscore-min", } } var callbacks = this._make_callbacks(cell); - var data = {'custom_content': content}; + var data = {method: 'custom', custom_content: content}; this.comm.send(data, callbacks); }, @@ -156,7 +156,7 @@ define(["components/underscore/underscore-min", if (selector === undefined) { selector = ''; } - + var class_list = msg.content.data.class_list; this._execute_views_method(method, selector, class_list); break; @@ -253,7 +253,7 @@ define(["components/underscore/underscore-min", } } - var data = {sync_method: method, sync_data: send_json}; + var data = {method: 'backbone', sync_method: method, sync_data: send_json}; var cell = null; if (this.last_modified_view != undefined && this.last_modified_view != null) { diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py index 2e8fb05a0..7b109b5b5 100644 --- a/IPython/html/widgets/widget.py +++ b/IPython/html/widgets/widget.py @@ -113,16 +113,19 @@ class Widget(LoggingConfigurable): def _handle_msg(self, msg): """Called when a msg is recieved from the frontend""" data = msg['content']['data'] - + method = data['method'] + # Handle backbone sync methods CREATE, PATCH, and UPDATE - if 'sync_method' in data and 'sync_data' in data: - sync_method = data['sync_method'] - sync_data = data['sync_data'] - self._handle_recieve_state(sync_data) # handles all methods + if method == 'backbone': + if 'sync_method' in data and 'sync_data' in data: + sync_method = data['sync_method'] + sync_data = data['sync_data'] + self._handle_recieve_state(sync_data) # handles all methods # Handle a custom msg from the front-end - if 'custom_content' in data: - self._handle_custom_msg(data['custom_content']) + elif method == 'custom': + if 'custom_content' in data: + self._handle_custom_msg(data['custom_content']) def _handle_custom_msg(self, content):