-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmodel.ts
51 lines (43 loc) · 1.37 KB
/
model.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
import { IDisposable } from '@lumino/disposable';
import { IJupyterYModel } from '../types';
import { IJupyterYWidgetManager } from './types';
export class NotebookRendererModel implements IDisposable {
constructor(options: NotebookRendererModel.IOptions) {
this._widgetManager = options.widgetManager;
this._kernelOrNotebookId = options.kernelOrNotebookId;
}
get isDisposed(): boolean {
return this._isDisposed;
}
dispose(): void {
if (this._isDisposed) {
return;
}
this._isDisposed = true;
}
getYModel(commOrRoomId: string): IJupyterYModel | undefined {
if (this._kernelOrNotebookId) {
return this._widgetManager.getWidgetModel(this._kernelOrNotebookId, commOrRoomId);
}
}
createYWidget(commOrRoomId: string, node: HTMLElement): void {
if (this._kernelOrNotebookId) {
const yModel = this._widgetManager.getWidgetModel(this._kernelOrNotebookId, commOrRoomId);
if (yModel) {
const widgetFactory = this._widgetManager.getWidgetFactory(
yModel.yModelName
);
new widgetFactory(yModel, node);
}
}
}
private _isDisposed = false;
private _kernelOrNotebookId?: string;
private _widgetManager: IJupyterYWidgetManager;
}
export namespace NotebookRendererModel {
export interface IOptions {
kernelOrNotebookId?: string;
widgetManager: IJupyterYWidgetManager;
}
}