Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace existing Comm on open #104

Merged
merged 12 commits into from
Mar 25, 2024
21 changes: 11 additions & 10 deletions ipywidgets_bokeh/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as controls from "@jupyter-widgets/controls"

import {HTMLManager} from "@jupyter-widgets/html-manager"
import {WidgetModel, WidgetView, IModelOptions, IClassicComm, shims} from "@jupyter-widgets/base"
import {WidgetModel, WidgetView, IModelOptions, shims} from "@jupyter-widgets/base"
import {IState, IManagerState} from "@jupyter-widgets/base-manager"

import {Kernel, KernelManager, ServerConnection} from "@jupyterlab/services"
Expand Down Expand Up @@ -131,13 +131,12 @@
const comm_wrapper = new shims.services.Comm(comm)
if (model == null) {
this.handle_comm_open(comm_wrapper, msg).then((model) => {
if (model != null && !model.comm_live) {

Check warning on line 134 in ipywidgets_bokeh/src/manager.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18.x)

Unnecessary conditional, the types have no overlap

Check warning on line 134 in ipywidgets_bokeh/src/manager.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, 18.x)

Unnecessary conditional, the types have no overlap

Check warning on line 134 in ipywidgets_bokeh/src/manager.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 18.x)

Unnecessary conditional, the types have no overlap
const comm_wrapper = new shims.services.Comm(comm)
this._attach_comm(comm_wrapper, model)
}
})
}
if (model != null && !model.comm_live) {
} else {
this._attach_comm(comm_wrapper, model)
}
this._model_objs.delete(msg.content.comm_id)
Expand Down Expand Up @@ -191,17 +190,19 @@
}

override async _create_comm(target_name: string, model_id: string, data?: any, metadata?: any,
buffers?: ArrayBuffer[] | ArrayBufferView[]): Promise<IClassicComm> {
buffers?: ArrayBuffer[] | ArrayBufferView[]): Promise<shims.services.Comm> {
const comm = (() => {
const key = target_name + model_id
const comm = this._comms.get(key)
if (comm != null)
return comm
else {
const comm = this.kernel.createComm(target_name, model_id)
let comm = this._comms.get(key)
mattpap marked this conversation as resolved.
Show resolved Hide resolved
if (comm == null) {
if (this.kernel.hasComm(model_id)) {
comm = (this.kernel as any)._comms.get(model_id)
mattpap marked this conversation as resolved.
Show resolved Hide resolved
} else {
comm = this.kernel.createComm(target_name, model_id)
}
this._comms.set(key, comm)
return comm
}
return comm
})()
comm.open(data, metadata, buffers)
return new shims.services.Comm(comm)
Expand Down
Loading