diff --git a/IPython/html/static/notebook/js/widgetmanager.js b/IPython/html/static/notebook/js/widgetmanager.js
index 20cdf90..8bc511e 100644
--- a/IPython/html/static/notebook/js/widgetmanager.js
+++ b/IPython/html/static/notebook/js/widgetmanager.js
@@ -95,10 +95,9 @@
var view = new ViewType({model: model, widget_manager: this, cell: cell});
view.render();
model.views.push(view);
+ model.on('destroy', view.remove, view);
/*
- // jng: Handle when the view element is remove from the page.
- // observe the view destruction event and do this. We may need
- // to override the view's remove method to trigger this event.
+ // TODO: handle view deletion. Don't forget to delete child views
var that = this;
view.$el.on("remove", function () {
var index = that.views.indexOf(view);
@@ -109,7 +108,7 @@
// Close the comm if there are no views left.
if (that.views.length() === 0) {
- //jng: trigger comm close event
+ //trigger comm close event?
}
diff --git a/IPython/html/static/notebook/js/widgets/base.js b/IPython/html/static/notebook/js/widgets/base.js
index 675f98d..fcc30c5 100644
--- a/IPython/html/static/notebook/js/widgets/base.js
+++ b/IPython/html/static/notebook/js/widgets/base.js
@@ -41,7 +41,6 @@ function(widget_manager, underscore, backbone){
comm.on_close($.proxy(this._handle_comm_closed, this));
comm.on_msg($.proxy(this._handle_comm_msg, this));
}
-
return Backbone.Model.apply(this);
},
@@ -54,12 +53,11 @@ 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;
delete this.widget_id; // Delete id from model so widget manager cleans up.
+ // TODO: Handle deletion, like this.destroy(), and delete views, etc.
},