Skip to content

Commit a4dd288

Browse files
committed
Convert widgetsnbextension output widget to es2015 modules
1 parent a386214 commit a4dd288

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

widgetsnbextension/src/widget_output.js

+28-32
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@
44

55
// This widget is strongly coupled to the notebook because of the outputarea
66
// dependency.
7-
var widgets = require("@jupyter-widgets/controls");
87
var outputBase = require("@jupyter-widgets/output");
9-
var _ = require("underscore");
108
require('./widget_output.css');
119

1210
var outputArea = new Promise(function(resolve, reject) {
1311
requirejs(["notebook/js/outputarea"], resolve, reject)
1412
});
1513

16-
var OutputModel = outputBase.OutputModel.extend({
17-
defaults: _.extend({}, outputBase.OutputModel.prototype.defaults(), {
18-
msg_id: "",
19-
outputs: []
20-
}),
14+
export class OutputModel extends outputBase.OutputModel {
15+
defaults() {
16+
return {
17+
...super.defaults(),
18+
msg_id: "",
19+
outputs: []
20+
}
21+
}
2122

22-
initialize: function(attributes, options) {
23-
OutputModel.__super__.initialize.apply(this, arguments);
23+
initialize(attributes, options) {
24+
super.initialize(attributes, options)
2425
this.listenTo(this, 'change:msg_id', this.reset_msg_id);
2526

2627
if (this.comm && this.comm.kernel) {
@@ -50,14 +51,14 @@ var OutputModel = outputBase.OutputModel.extend({
5051
that.listenTo(that, 'change:outputs', that.setOutputs);
5152
that.setOutputs();
5253
});
53-
},
54+
}
5455

5556
// make callbacks
56-
callbacks: function() {
57+
callbacks() {
5758
// Merge our callbacks with the base class callbacks.
58-
var cb = OutputModel.__super__.callbacks.apply(this, arguments);
59+
var cb = super.callbacks();
5960
var iopub = cb.iopub || {};
60-
var iopubCallbacks = _.extend({}, iopub, {
61+
var iopubCallbacks = {...iopub,
6162
output: function(msg) {
6263
this.trigger('new_message', msg);
6364
if (iopub.output) {
@@ -70,11 +71,11 @@ var OutputModel = outputBase.OutputModel.extend({
7071
iopub.clear_output.apply(this, arguments);
7172
}
7273
}.bind(this)
73-
});
74-
return _.extend({}, cb, {iopub: iopubCallbacks});
75-
},
74+
};
75+
return {...cb, iopub: iopubCallbacks};
76+
}
7677

77-
reset_msg_id: function() {
78+
reset_msg_id() {
7879
var kernel = this.kernel;
7980
// Pop previous message id
8081
var prev_msg_id = this.previous('msg_id');
@@ -88,21 +89,21 @@ var OutputModel = outputBase.OutputModel.extend({
8889
if (msg_id && kernel) {
8990
kernel.output_callback_overrides_push(msg_id, this.model_id);
9091
}
91-
},
92+
}
9293

93-
setOutputs: function(model, value, options) {
94+
setOutputs(model, value, options) {
9495
if (!(options && options.newMessage)) {
9596
// fromJSON does not clear the existing output
9697
this.output_area.clear_output();
9798
// fromJSON does not copy the message, so we make a deep copy
9899
this.output_area.fromJSON(JSON.parse(JSON.stringify(this.get('outputs'))));
99100
}
100-
},
101+
}
101102

102-
});
103+
}
103104

104-
var OutputView = outputBase.OutputView.extend({
105-
render: function(){
105+
export class OutputView extends outputBase.OutputView {
106+
render(){
106107
var that = this;
107108
this.el.classList.add('jupyter-widgets-output-area');
108109
outputArea.then(function(outputArea) {
@@ -128,20 +129,15 @@ var OutputView = outputBase.OutputView.extend({
128129
that.listenTo(that.model, 'change:outputs', that.setOutputs);
129130
that.setOutputs();
130131
});
131-
OutputView.__super__.render.apply(this, arguments);
132-
},
132+
super.render();
133+
}
133134

134-
setOutputs: function(model, value, options) {
135+
setOutputs(model, value, options) {
135136
if (!(options && options.newMessage)) {
136137
// fromJSON does not clear the existing output
137138
this.output_area.clear_output();
138139
// fromJSON does not copy the message, so we make a deep copy
139140
this.output_area.fromJSON(JSON.parse(JSON.stringify(this.model.get('outputs'))));
140141
}
141142
}
142-
});
143-
144-
module.exports = {
145-
OutputView: OutputView,
146-
OutputModel: OutputModel,
147-
};
143+
}

0 commit comments

Comments
 (0)