4
4
5
5
// This widget is strongly coupled to the notebook because of the outputarea
6
6
// dependency.
7
- var widgets = require ( "@jupyter-widgets/controls" ) ;
8
7
var outputBase = require ( "@jupyter-widgets/output" ) ;
9
- var _ = require ( "underscore" ) ;
10
8
require ( './widget_output.css' ) ;
11
9
12
10
var outputArea = new Promise ( function ( resolve , reject ) {
13
11
requirejs ( [ "notebook/js/outputarea" ] , resolve , reject )
14
12
} ) ;
15
13
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
+ }
21
22
22
- initialize : function ( attributes , options ) {
23
- OutputModel . __super__ . initialize . apply ( this , arguments ) ;
23
+ initialize ( attributes , options ) {
24
+ super . initialize ( attributes , options )
24
25
this . listenTo ( this , 'change:msg_id' , this . reset_msg_id ) ;
25
26
26
27
if ( this . comm && this . comm . kernel ) {
@@ -50,14 +51,14 @@ var OutputModel = outputBase.OutputModel.extend({
50
51
that . listenTo ( that , 'change:outputs' , that . setOutputs ) ;
51
52
that . setOutputs ( ) ;
52
53
} ) ;
53
- } ,
54
+ }
54
55
55
56
// make callbacks
56
- callbacks : function ( ) {
57
+ callbacks ( ) {
57
58
// Merge our callbacks with the base class callbacks.
58
- var cb = OutputModel . __super__ . callbacks . apply ( this , arguments ) ;
59
+ var cb = super . callbacks ( ) ;
59
60
var iopub = cb . iopub || { } ;
60
- var iopubCallbacks = _ . extend ( { } , iopub , {
61
+ var iopubCallbacks = { ... iopub ,
61
62
output : function ( msg ) {
62
63
this . trigger ( 'new_message' , msg ) ;
63
64
if ( iopub . output ) {
@@ -70,11 +71,11 @@ var OutputModel = outputBase.OutputModel.extend({
70
71
iopub . clear_output . apply ( this , arguments ) ;
71
72
}
72
73
} . bind ( this )
73
- } ) ;
74
- return _ . extend ( { } , cb , { iopub : iopubCallbacks } ) ;
75
- } ,
74
+ } ;
75
+ return { ... cb , iopub : iopubCallbacks } ;
76
+ }
76
77
77
- reset_msg_id : function ( ) {
78
+ reset_msg_id ( ) {
78
79
var kernel = this . kernel ;
79
80
// Pop previous message id
80
81
var prev_msg_id = this . previous ( 'msg_id' ) ;
@@ -88,21 +89,21 @@ var OutputModel = outputBase.OutputModel.extend({
88
89
if ( msg_id && kernel ) {
89
90
kernel . output_callback_overrides_push ( msg_id , this . model_id ) ;
90
91
}
91
- } ,
92
+ }
92
93
93
- setOutputs : function ( model , value , options ) {
94
+ setOutputs ( model , value , options ) {
94
95
if ( ! ( options && options . newMessage ) ) {
95
96
// fromJSON does not clear the existing output
96
97
this . output_area . clear_output ( ) ;
97
98
// fromJSON does not copy the message, so we make a deep copy
98
99
this . output_area . fromJSON ( JSON . parse ( JSON . stringify ( this . get ( 'outputs' ) ) ) ) ;
99
100
}
100
- } ,
101
+ }
101
102
102
- } ) ;
103
+ }
103
104
104
- var OutputView = outputBase . OutputView . extend ( {
105
- render : function ( ) {
105
+ export class OutputView extends outputBase . OutputView {
106
+ render ( ) {
106
107
var that = this ;
107
108
this . el . classList . add ( 'jupyter-widgets-output-area' ) ;
108
109
outputArea . then ( function ( outputArea ) {
@@ -128,20 +129,15 @@ var OutputView = outputBase.OutputView.extend({
128
129
that . listenTo ( that . model , 'change:outputs' , that . setOutputs ) ;
129
130
that . setOutputs ( ) ;
130
131
} ) ;
131
- OutputView . __super__ . render . apply ( this , arguments ) ;
132
- } ,
132
+ super . render ( ) ;
133
+ }
133
134
134
- setOutputs : function ( model , value , options ) {
135
+ setOutputs ( model , value , options ) {
135
136
if ( ! ( options && options . newMessage ) ) {
136
137
// fromJSON does not clear the existing output
137
138
this . output_area . clear_output ( ) ;
138
139
// fromJSON does not copy the message, so we make a deep copy
139
140
this . output_area . fromJSON ( JSON . parse ( JSON . stringify ( this . model . get ( 'outputs' ) ) ) ) ;
140
141
}
141
142
}
142
- } ) ;
143
-
144
- module . exports = {
145
- OutputView : OutputView ,
146
- OutputModel : OutputModel ,
147
- } ;
143
+ }
0 commit comments