-
Notifications
You must be signed in to change notification settings - Fork 68
/
manager.js
71 lines (61 loc) · 1.88 KB
/
manager.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as pWidget from "@lumino/widgets";
import { HTMLManager } from "@jupyter-widgets/html-manager";
import * as outputWidgets from "./output";
import { ShimmedComm } from "./services-shim";
export class ThebeManager extends HTMLManager {
get onError() {
return this._onError;
}
registerWithKernel(kernel) {
if (this._commRegistration) {
this._commRegistration.dispose();
}
this._commRegistration = kernel.registerCommTarget(
this.comm_target_name,
(comm, message) => this.handle_comm_open(new ShimmedComm(comm), message)
);
}
display_view(msg, view, options) {
const el = options.el;
return Promise.resolve(view).then((view) => {
pWidget.Widget.attach(view.pWidget, el);
view.on("remove", function () {
console.log("view removed", view);
});
return view;
});
}
loadClass(className, moduleName, moduleVersion) {
if (moduleName === "@jupyter-widgets/output") {
return Promise.resolve(outputWidgets).then((module) => {
if (module[className]) {
return module[className];
} else {
return Promise.reject(
`Class ${className} not found in module ${moduleName}`
);
}
});
} else {
return super.loadClass(className, moduleName, moduleVersion);
}
}
callbacks(view) {
const baseCallbacks = super.callbacks(view);
return Object.assign({}, baseCallbacks, {
iopub: { output: (msg) => this._onError.emit(msg) },
});
}
_create_comm(target_name, model_id, data, metadata) {
const comm = this.kernel.connectToComm(target_name, model_id);
if (data || metdata) {
comm.open(data, metadata);
}
return Promise.resolve(new ShimmedComm(comm));
}
_get_comm_info() {
return this.kernel
.requestCommInfo({ target: this.comm_target_name })
.then((reply) => reply.content.comms);
}
}