From 3c96e03792868a34d0ebd8f454b208512ac6f297 2014-01-24 20:32:19 From: Jonathan Frederic Date: 2014-01-24 20:32:19 Subject: [PATCH] Fixed bug in throttling code. --- diff --git a/IPython/html/static/notebook/js/widgetmanager.js b/IPython/html/static/notebook/js/widgetmanager.js index f61e573..1401156 100644 --- a/IPython/html/static/notebook/js/widgetmanager.js +++ b/IPython/html/static/notebook/js/widgetmanager.js @@ -160,9 +160,13 @@ WidgetManager.prototype.callbacks = function (view) { // callback handlers specific a view var callbacks = {}; - var cell = view.options.cell; - if (cell !== null) { + if (view !== undefined && + view !== null && + view.options.cell !== undefined && + view.options.cell !== null) { + // Try to get output handlers + var cell = view.options.cell; var handle_output = null; var handle_clear_output = null; if (cell.output_area !== undefined && cell.output_area !== null) { diff --git a/IPython/html/static/notebook/js/widgets/widget.js b/IPython/html/static/notebook/js/widgets/widget.js index b008045..ce22e59 100644 --- a/IPython/html/static/notebook/js/widgets/widget.js +++ b/IPython/html/static/notebook/js/widgets/widget.js @@ -56,6 +56,7 @@ function(WidgetManager, Underscore, Backbone){ if (this.comm !== undefined) { var data = {method: 'custom', content: content}; this.comm.send(data, callbacks); + this.pending_msgs++; } }, @@ -158,7 +159,13 @@ function(WidgetManager, Underscore, Backbone){ // Only sync if there are attributes to send to the back-end. if (_.size(attrs) > 0) { - var callbacks = options.callbacks || {}; + + // If this message was sent via backbone itself, it will not + // have any callbacks. It's important that we create callbacks + // so we can listen for status messages, etc... + var callbacks = options.callbacks || this.callbacks(); + + // Check throttle. if (this.pending_msgs >= this.msg_throttle) { // The throttle has been exceeded, buffer the current msg so // it can be sent once the kernel has finished processing @@ -181,8 +188,7 @@ function(WidgetManager, Underscore, Backbone){ } else { // We haven't exceeded the throttle, send the message like - // normal. If this is a patch operation, just send the - // changes. + // normal. var data = {method: 'backbone', sync_data: attrs}; this.comm.send(data, callbacks); this.pending_msgs++; diff --git a/IPython/html/static/notebook/js/widgets/widget_string.js b/IPython/html/static/notebook/js/widgets/widget_string.js index 62612b8..7ae3890 100644 --- a/IPython/html/static/notebook/js/widgets/widget_string.js +++ b/IPython/html/static/notebook/js/widgets/widget_string.js @@ -176,8 +176,8 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){ }, handleChanging: function(e) { - // Handles and validates user input. - + // Handles user input. + // Calling model.set will trigger all of the other views of the // model to update. this.model.set('value', e.target.value, {updated_view: this});