Skip to content

Commit

Permalink
Rename the widget model .id attribute to .model_id
Browse files Browse the repository at this point in the history
In Backbone, it will set the .id attribute automatically based on model data. This also may mean that it will make the .id attribute undefined after we have set it.
  • Loading branch information
jasongrout committed Jun 24, 2017
1 parent b3e0c81 commit 1046670
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
7 changes: 3 additions & 4 deletions jupyter-widgets-base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class WidgetModel extends Backbone.Model {
super.initialize(attributes, options);

this.widget_manager = options.widget_manager;
this.id = options.model_id;
this.model_id = options.model_id;
let comm = options.comm;

// _buffered_state_diff must be created *after* the super.initialize
Expand Down Expand Up @@ -186,7 +186,7 @@ class WidgetModel extends Backbone.Model {
return (this.constructor as typeof WidgetModel)._deserialize_state(state, this.widget_manager);
}).then((state) => {
this.set_state(state);
}).catch(utils.reject(`Could not process update msg for model id: ${this.id}`, true))
}).catch(utils.reject(`Could not process update msg for model id: ${this.model_id}`, true))
return this.state_change;
case 'custom':
this.trigger('msg:custom', msg.content.data.content, msg.buffers);
Expand Down Expand Up @@ -467,7 +467,7 @@ class WidgetModel extends Backbone.Model {
* and the kernel-side serializer/deserializer.
*/
toJSON(options) {
return `IPY_MODEL_${this.id}`;
return `IPY_MODEL_${this.model_id}`;
}

/**
Expand Down Expand Up @@ -686,7 +686,6 @@ class DOMWidgetView extends WidgetView {
*/
initialize(parameters) {
super.initialize(parameters);
this.id = utils.uuid();

this.listenTo(this.model, 'change:_dom_classes', (model, new_classes) => {
let old_classes = model.previous('_dom_classes');
Expand Down
2 changes: 1 addition & 1 deletion jupyter-widgets-htmlmanager/src/embed-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function renderManager(element, tag) {
}
let model_id = widgetViewObject.model_id;
let model = _.find(models, function(item : WidgetModel) {
return item.id == model_id;
return item.model_id == model_id;
});
if (model !== undefined) {
if (viewtag.previousElementSibling &&
Expand Down
8 changes: 4 additions & 4 deletions widgetsnbextension/src/widget_output.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var OutputModel = widgets.DOMWidgetModel.extend({
this.kernel = this.comm.kernel;
this.listenTo(this, 'change:msg_id', this.reset_msg_id);
if (this.kernel) {
this.kernel.set_callbacks_for_msg(this.id, this.callbacks(), false);
this.kernel.set_callbacks_for_msg(this.model_id, this.callbacks(), false);
}

var that = this;
Expand Down Expand Up @@ -80,13 +80,13 @@ var OutputModel = widgets.DOMWidgetModel.extend({
var prev_msg_id = this.previous('msg_id');
if (prev_msg_id && kernel) {
var previous_callback = kernel.output_callback_overrides_pop(prev_msg_id);
if (previous_callback !== this.id) {
console.error('Popped wrong message ('+previous_callback+' instead of '+this.id+') - likely the stack was not maintained in kernel.');
if (previous_callback !== this.model_id) {
console.error('Popped wrong message ('+previous_callback+' instead of '+this.model_id+') - likely the stack was not maintained in kernel.');
}
}
var msg_id = this.get('msg_id');
if (msg_id && kernel) {
kernel.output_callback_overrides_push(msg_id, this.id);
kernel.output_callback_overrides_push(msg_id, this.model_id);
}
},

Expand Down

0 comments on commit 1046670

Please sign in to comment.