From 9a4c5957c3220d2cbf121755d61b70b1b409c154 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Tue, 31 Dec 2013 12:58:58 -0700 Subject: [PATCH] Store views in the models and store child views in the views --- IPython/html/static/notebook/js/widgetmanager.js | 3 +-- IPython/html/static/notebook/js/widgets/base.js | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/IPython/html/static/notebook/js/widgetmanager.js b/IPython/html/static/notebook/js/widgetmanager.js index d35bbf153..b3640e2f5 100644 --- a/IPython/html/static/notebook/js/widgetmanager.js +++ b/IPython/html/static/notebook/js/widgetmanager.js @@ -98,8 +98,7 @@ if (ViewType !== undefined && ViewType !== null) { var view = new ViewType({model: model, widget_manager: this, cell: cell}); view.render(); - //this.views.push(view); - + model.views.push(view); /* // jng: Handle when the view element is remove from the page. // observe the view destruction event and do this. We may need diff --git a/IPython/html/static/notebook/js/widgets/base.js b/IPython/html/static/notebook/js/widgets/base.js index 09d5298ba..675f98d0e 100644 --- a/IPython/html/static/notebook/js/widgets/base.js +++ b/IPython/html/static/notebook/js/widgets/base.js @@ -29,6 +29,7 @@ function(widget_manager, underscore, backbone){ this.msg_throttle = 3; this.msg_buffer = null; this.id = widget_id; + this.views = []; if (comm !== undefined) { // Remember comm associated with the model. @@ -43,7 +44,6 @@ function(widget_manager, underscore, backbone){ return Backbone.Model.apply(this); }, - send: function (content, callbacks) { if (this.comm !== undefined) { @@ -55,6 +55,7 @@ function(widget_manager, underscore, backbone){ // Handle when a widget is closed. _handle_comm_closed: function (msg) { // jng: widget manager should observe the comm_close event and delete views when triggered + this.trigger('comm:close'); delete this.comm.model; // Delete ref so GC will collect widget model. delete this.comm; @@ -178,6 +179,7 @@ function(widget_manager, underscore, backbone){ this.widget_manager = options.widget_manager; this.comm_manager = options.widget_manager.comm_manager; this.cell = options.cell; + this.child_views = []; }, update: function(){ @@ -187,6 +189,7 @@ function(widget_manager, underscore, backbone){ child_view: function(comm_id, view_name) { var child_model = this.comm_manager.comms[comm_id].model; var child_view = this.widget_manager.create_view(child_model, view_name, this.cell); + this.child_views.push(child_view); return child_view; },