From e8cb71d7e5baed521392529ef4daf8ab14da8b70 2014-11-15 16:48:35 From: Jonathan Frederic Date: 2014-11-15 16:48:35 Subject: [PATCH] Move the display Promise into a lower level method, into the create view method of the widget manager. This makes sure that views created by parent views are also accounted for in the state/display order guarantee. --- diff --git a/IPython/html/static/widgets/js/manager.js b/IPython/html/static/widgets/js/manager.js index 7f3f70e..e98a350 100644 --- a/IPython/html/static/widgets/js/manager.js +++ b/IPython/html/static/widgets/js/manager.js @@ -93,7 +93,12 @@ define([ WidgetManager.prototype.create_view = function(model, options) { // Creates a promise for a view of a given model - return utils.load_class(model.get('_view_name'), model.get('_view_module'), + + // Make sure the view creation is not out of order with + // any state updates. + model.state_change = model.state_change.then(function() { + console.log('create_view ' + model.id); + return utils.load_class(model.get('_view_name'), model.get('_view_module'), WidgetManager._view_types).then(function(ViewType) { // If a view is passed into the method, use that view's cell as @@ -109,6 +114,8 @@ define([ view.render(); return view; }, utils.reject("Couldn't create a view for model id '" + String(model.id) + "'")); + }); + return model.state_change; }; WidgetManager.prototype.get_msg_cell = function (msg_id) { diff --git a/IPython/html/static/widgets/js/widget.js b/IPython/html/static/widgets/js/widget.js index 9d98bed..42ea44f 100644 --- a/IPython/html/static/widgets/js/widget.js +++ b/IPython/html/static/widgets/js/widget.js @@ -81,9 +81,8 @@ define(["widgets/js/manager", this.trigger('msg:custom', msg.content.data.content); break; case 'display': - this.state_change = this.state_change.then(function () { - return that.widget_manager.display_view(msg, that); - }).catch(utils.reject("Couldn't process display msg for model id '" + String(that.id) + "'", true)); + that.widget_manager.display_view(msg, that) + .catch(utils.reject("Couldn't process display msg for model id '" + String(that.id) + "'", true)); break; } }, @@ -94,6 +93,8 @@ define(["widgets/js/manager", return this._unpack_models(state).then(function(state) { that.state_lock = state; try { + console.log('set_state ' + that.id); + console.log(state); WidgetModel.__super__.set.call(that, state); } finally { that.state_lock = null;