##// END OF EJS Templates
Re-decoupled comm_id from widget models
Jonathan Frederic -
Show More
@@ -66,6 +66,8 b''
66 66 WidgetManager.prototype.register_widget_view = function (widget_view_name, widget_view_type) {
67 67 this.widget_view_types[widget_view_name] = widget_view_type;
68 68 };
69
70
69 71 WidgetManager.prototype.handle_msg = function(msg, model) {
70 72 var method = msg.content.data.method;
71 73 switch (method) {
@@ -117,7 +119,7 b''
117 119 delete that.comm.model; // Delete ref so GC will collect widget model.
118 120 delete that.comm;
119 121 }
120 delete that.widget_id; // Delete id from model so widget manager cleans up.
122 delete that.model_id; // Delete id from model so widget manager cleans up.
121 123 });
122 124 */
123 125 return view;
@@ -154,9 +156,9 b''
154 156 };
155 157
156 158
157 WidgetManager.prototype.get_model = function (widget_id) {
158 var model = this._model_instances[widget_id];
159 if (model !== undefined && model.id == widget_id) {
159 WidgetManager.prototype.get_model = function (model_id) {
160 var model = this._model_instances[model_id];
161 if (model !== undefined && model.id == model_id) {
160 162 return model;
161 163 }
162 164 return null;
@@ -191,7 +193,7 b''
191 193 WidgetManager.prototype._handle_comm_open = function (comm, msg) {
192 194 var widget_type_name = msg.content.target_name;
193 195 var widget_model = new this.widget_model_types[widget_type_name](this, comm.comm_id, comm);
194 this._model_instances[comm.comm_id] = widget_model;
196 this._model_instances[comm.comm_id] = widget_model; // comm_id == model_id
195 197 this._handle_create_widget(widget_model);
196 198 };
197 199
@@ -23,12 +23,12 b' function(widget_manager, underscore, backbone){'
23 23 // WidgetModel class
24 24 //--------------------------------------------------------------------
25 25 var WidgetModel = Backbone.Model.extend({
26 constructor: function (widget_manager, widget_id, comm) {
26 constructor: function (widget_manager, model_id, comm) {
27 27 this.widget_manager = widget_manager;
28 28 this.pending_msgs = 0;
29 29 this.msg_throttle = 3;
30 30 this.msg_buffer = null;
31 this.id = widget_id;
31 this.id = model_id;
32 32 this.views = [];
33 33
34 34 if (comm !== undefined) {
@@ -55,7 +55,7 b' function(widget_manager, underscore, backbone){'
55 55 this.trigger('comm:close');
56 56 delete this.comm.model; // Delete ref so GC will collect widget model.
57 57 delete this.comm;
58 delete this.widget_id; // Delete id from model so widget manager cleans up.
58 delete this.model_id; // Delete id from model so widget manager cleans up.
59 59 // TODO: Handle deletion, like this.destroy(), and delete views, etc.
60 60 },
61 61
@@ -181,12 +181,12 b' function(widget_manager, underscore, backbone){'
181 181 // triggered on model change
182 182 },
183 183
184 child_view: function(comm_id, view_name) {
184 child_view: function(model_id, view_name) {
185 185 // create and return a child view, given a comm id for a model and (optionally) a view name
186 186 // if the view name is not given, it defaults to the model's default view attribute
187 var child_model = this.comm_manager.comms[comm_id].model;
187 var child_model = this.widget_manager.get_model(model_id);
188 188 var child_view = this.widget_manager.create_view(child_model, view_name, this.cell);
189 this.child_views[comm_id] = child_view;
189 this.child_views[model_id] = child_view;
190 190 return child_view;
191 191 },
192 192
@@ -100,6 +100,10 b' class BaseWidget(LoggingConfigurable):'
100 100 self._open_communication()
101 101 return self._comm
102 102
103 @property
104 def model_id(self):
105 return self._comm.comm_id
106
103 107 # Event handlers
104 108 def _handle_msg(self, msg):
105 109 """Called when a msg is recieved from the frontend"""
@@ -220,10 +224,10 b' class BaseWidget(LoggingConfigurable):'
220 224 # encoder to look for a _repr_json property before giving
221 225 # up encoding
222 226 if isinstance(value, BaseWidget):
223 value = value.comm.comm_id
227 value = value.model_id
224 228 elif isinstance(value, list) and len(value)>0 and isinstance(value[0], BaseWidget):
225 229 # assume all elements of the list are widgets
226 value = [i.comm.comm_id for i in value]
230 value = [i.model_id for i in value]
227 231 state[k] = value
228 232 return state
229 233
General Comments 0
You need to be logged in to leave comments. Login now