##// END OF EJS Templates
Separate widget model name from com target name.
Jonathan Frederic -
Show More
@@ -21,11 +21,8 b' define(['
21 this.comm_manager = comm_manager;
21 this.comm_manager = comm_manager;
22 this._models = {}; /* Dictionary of model ids and model instances */
22 this._models = {}; /* Dictionary of model ids and model instances */
23
23
24 // Register already-registered widget model types with the comm manager.
24 // Register with the comm manager.
25 var that = this;
25 this.comm_manager.register_target('ipython.widget', $.proxy(this._handle_comm_open, this));
26 _.each(WidgetManager._model_types, function(model_type, model_name) {
27 that.comm_manager.register_target(model_name, $.proxy(that._handle_comm_open, that));
28 });
29 };
26 };
30
27
31 //--------------------------------------------------------------------
28 //--------------------------------------------------------------------
@@ -38,14 +35,6 b' define(['
38 WidgetManager.register_widget_model = function (model_name, model_type) {
35 WidgetManager.register_widget_model = function (model_name, model_type) {
39 // Registers a widget model by name.
36 // Registers a widget model by name.
40 WidgetManager._model_types[model_name] = model_type;
37 WidgetManager._model_types[model_name] = model_type;
41
42 // Register the widget with the comm manager. Make sure to pass this object's context
43 // in so `this` works in the call back.
44 _.each(WidgetManager._managers, function(instance, i) {
45 if (instance.comm_manager !== null) {
46 instance.comm_manager.register_target(model_name, $.proxy(instance._handle_comm_open, instance));
47 }
48 });
49 };
38 };
50
39
51 WidgetManager.register_widget_view = function (view_name, view_type) {
40 WidgetManager.register_widget_view = function (view_name, view_type) {
@@ -186,7 +175,7 b' define(['
186 // Handle when a comm is opened.
175 // Handle when a comm is opened.
187 var that = this;
176 var that = this;
188 var model_id = comm.comm_id;
177 var model_id = comm.comm_id;
189 var widget_type_name = msg.content.target_name;
178 var widget_type_name = msg.content.data.target_name;
190 var widget_model = new WidgetManager._model_types[widget_type_name](this, model_id, comm);
179 var widget_model = new WidgetManager._model_types[widget_type_name](this, model_id, comm);
191 widget_model.on('comm:close', function () {
180 widget_model.on('comm:close', function () {
192 delete that._models[model_id];
181 delete that._models[model_id];
@@ -140,11 +140,12 b' class Widget(LoggingConfigurable):'
140 def open(self):
140 def open(self):
141 """Open a comm to the frontend if one isn't already open."""
141 """Open a comm to the frontend if one isn't already open."""
142 if self.comm is None:
142 if self.comm is None:
143 if self._model_id is None:
143 args = dict(target_name='ipython.widget', data={ 'target_name': self._model_name })
144 self.comm = Comm(target_name=self._model_name)
144 if self._model_id is not None:
145 self._model_id = self.model_id
145 args['comm_id'] = self._model_id
146 else:
146 self.comm = Comm(**args)
147 self.comm = Comm(target_name=self._model_name, comm_id=self._model_id)
147 self._model_id = self.model_id
148
148 self.comm.on_msg(self._handle_msg)
149 self.comm.on_msg(self._handle_msg)
149 Widget.widgets[self.model_id] = self
150 Widget.widgets[self.model_id] = self
150
151
General Comments 0
You need to be logged in to leave comments. Login now