##// END OF EJS Templates
Make Widget.views be an object indexed by view id
Sylvain Corlay -
Show More
@@ -26,7 +26,7 b' define(["widgets/js/manager",'
26 this.msg_buffer = null;
26 this.msg_buffer = null;
27 this.state_lock = null;
27 this.state_lock = null;
28 this.id = model_id;
28 this.id = model_id;
29 this.views = [];
29 this.views = {};
30
30
31 if (comm !== undefined) {
31 if (comm !== undefined) {
32 // Remember comm associated with the model.
32 // Remember comm associated with the model.
@@ -57,9 +57,9 b' define(["widgets/js/manager",'
57 delete this.comm.model; // Delete ref so GC will collect widget model.
57 delete this.comm.model; // Delete ref so GC will collect widget model.
58 delete this.comm;
58 delete this.comm;
59 delete this.model_id; // Delete id from model so widget manager cleans up.
59 delete this.model_id; // Delete id from model so widget manager cleans up.
60 _.each(this.views, function(view, i) {
60 for (var id in this.views) {
61 view.remove();
61 this.views[id].remove();
62 });
62 }
63 },
63 },
64
64
65 _handle_comm_msg: function (msg) {
65 _handle_comm_msg: function (msg) {
@@ -293,8 +293,8 b' define(["widgets/js/manager",'
293 this.options = parameters.options;
293 this.options = parameters.options;
294 this.child_model_views = {};
294 this.child_model_views = {};
295 this.child_views = {};
295 this.child_views = {};
296 this.model.views.push(this);
297 this.id = this.id || IPython.utils.uuid();
296 this.id = this.id || IPython.utils.uuid();
297 this.model.views[this.id] = this;
298 this.on('displayed', function() {
298 this.on('displayed', function() {
299 this.is_displayed = true;
299 this.is_displayed = true;
300 }, this);
300 }, this);
@@ -339,7 +339,7 b' define(["widgets/js/manager",'
339 var view = this.child_views[view_id];
339 var view = this.child_views[view_id];
340 delete this.child_views[view_id];
340 delete this.child_views[view_id];
341 view_ids.splice(0,1);
341 view_ids.splice(0,1);
342 child_model.views.pop(view);
342 delete child_model.views[view_id];
343
343
344 // Remove the view list specific to this model if it is empty.
344 // Remove the view list specific to this model if it is empty.
345 if (view_ids.length === 0) {
345 if (view_ids.length === 0) {
General Comments 0
You need to be logged in to leave comments. Login now