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