2
0
mirror of https://github.com/jupyter/notebook.git synced 2025-02-23 12:49:41 +08:00

Make Widget.views be an object indexed by view id

This commit is contained in:
Sylvain Corlay 2014-09-26 01:50:04 +00:00
parent 3cb8c5a0a1
commit b6a0f60d3f

View File

@ -26,7 +26,7 @@ define(["widgets/js/manager",
this.msg_buffer = null;
this.state_lock = null;
this.id = model_id;
this.views = [];
this.views = {};
if (comm !== undefined) {
// Remember comm associated with the model.
@ -57,9 +57,9 @@ define(["widgets/js/manager",
delete this.comm.model; // Delete ref so GC will collect widget model.
delete this.comm;
delete this.model_id; // Delete id from model so widget manager cleans up.
_.each(this.views, function(view, i) {
view.remove();
});
for (var id in this.views) {
this.views[id].remove();
}
},
_handle_comm_msg: function (msg) {
@ -293,8 +293,8 @@ define(["widgets/js/manager",
this.options = parameters.options;
this.child_model_views = {};
this.child_views = {};
this.model.views.push(this);
this.id = this.id || IPython.utils.uuid();
this.model.views[this.id] = this;
this.on('displayed', function() {
this.is_displayed = true;
}, this);
@ -339,7 +339,7 @@ define(["widgets/js/manager",
var view = this.child_views[view_id];
delete this.child_views[view_id];
view_ids.splice(0,1);
child_model.views.pop(view);
delete child_model.views[view_id];
// Remove the view list specific to this model if it is empty.
if (view_ids.length === 0) {