forked from QuantStack/yjs-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.ts
56 lines (48 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
52
53
54
55
56
import { IDisposable } from '@lumino/disposable';
import { IJupyterYModel } from '../types';
import { IJupyterYWidget, IJupyterYWidgetManager } from './types';
export class NotebookRendererModel implements IDisposable {
constructor(options: NotebookRendererModel.IOptions) {
this._widgetManager = options.widgetManager;
this._kernelId = options.kernelId;
}
get isDisposed(): boolean {
return this._isDisposed;
}
dispose(): void {
if (this._isDisposed) {
return;
}
this._isDisposed = true;
}
getYModel(commId: string): IJupyterYModel | undefined {
if (this._kernelId) {
return this._widgetManager.getWidgetModel(this._kernelId, commId);
}
}
createYWidget(
commId: string,
node: HTMLElement
): IJupyterYWidget | undefined {
if (this._kernelId) {
const yModel = this._widgetManager.getWidgetModel(this._kernelId, commId);
if (yModel) {
const widgetFactory = this._widgetManager.getWidgetFactory(
yModel.yModelName
);
if (widgetFactory) {
return new widgetFactory(yModel, node);
}
}
}
}
private _isDisposed = false;
private _kernelId?: string;
private _widgetManager: IJupyterYWidgetManager;
}
export namespace NotebookRendererModel {
export interface IOptions {
kernelId?: string;
widgetManager: IJupyterYWidgetManager;
}
}