-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathview.ts
53 lines (45 loc) · 1.35 KB
/
view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Widget } from '@lumino/widgets';
//import { JupyterYWidget} from '../widget';
import { NotebookRendererModel } from './model';
import { IRenderMime } from '@jupyterlab/rendermime';
import { IJupyterYModel } from '../types';
export const CLASS_NAME = 'mimerenderer-jupyterywidget';
export class JupyterYWidget extends Widget implements IRenderMime.IRenderer {
/**
* Construct a new output widget.
*/
constructor(options: {
modelFactory: NotebookRendererModel;
mimeType: string;
}) {
super();
this._modelFactory = options.modelFactory;
this._mimeType = options.mimeType;
this.addClass(CLASS_NAME);
}
dispose(): void {
if (this.isDisposed) {
return;
}
this._yModel?.dispose();
super.dispose();
}
async renderModel(mimeModel: IRenderMime.IMimeModel): Promise<void> {
const modelId = mimeModel.data[this._mimeType]!['model_id'];
this._yModel = this._modelFactory.getYModel(modelId);
if (!this._yModel) {
return;
}
this._modelFactory.createYWidget(modelId, this.node);
}
render(roomId: string): void {
this._yModel = this._modelFactory.getYModel(roomId);
if (!this._yModel) {
return;
}
this._modelFactory.createYWidget(roomId, this.node);
}
private _modelFactory: NotebookRendererModel;
private _mimeType: string;
private _yModel?: IJupyterYModel;
}