Skip to content

Commit

Permalink
Remove rxjs from widgetManager (#14615)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Oct 30, 2023
1 parent f447111 commit a727344
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,7 @@
"webpack-analyze:web": "npx webpack --json --config build/webpack/webpack.extension.web.config.js > out/stats-web.json && yarn webpack-bundle-analyzer out/stats-web.json"
},
"dependencies": {
"@c4312/evt": "^0.1.1",
"@enonic/fnv-plus": "^1.3.0",
"@fluentui/react": "^7.160.1",
"@jupyter-widgets/base": "4.0.0",
Expand Down
7 changes: 5 additions & 2 deletions src/webviews/webview-side/ipywidgets/kernel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ let widgetManagerPromise: Promise<WidgetManager> | undefined;
async function getWidgetManager(): Promise<WidgetManager> {
if (!widgetManagerPromise) {
function reInitializeWidgetManager(resolve?: (value: WidgetManager) => void) {
WidgetManager.instance.subscribe((wm) => {
function initializeInstance() {
const wm = WidgetManager.instance;
if (wm) {
const oldDispose = wm.dispose.bind(wm);
wm.dispose = () => {
Expand All @@ -237,7 +238,9 @@ async function getWidgetManager(): Promise<WidgetManager> {
}
widgetManagerPromise = Promise.resolve(wm);
}
});
}
initializeInstance();
WidgetManager.onDidChangeInstance(initializeInstance);
}
// eslint-disable-next-line , @typescript-eslint/no-explicit-any
widgetManagerPromise = new Promise((resolve) => reInitializeWidgetManager(resolve as any));
Expand Down
16 changes: 9 additions & 7 deletions src/webviews/webview-side/ipywidgets/kernel/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import type { Kernel, KernelMessage } from '@jupyterlab/services';
import type * as nbformat from '@jupyterlab/nbformat';
import { Widget } from '@lumino/widgets';
import fastDeepEqual from 'fast-deep-equal';
import { Observable } from 'rxjs/Observable';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { EventEmitter, Event } from '@c4312/evt';
import { logMessage, setLogger } from '../../react-common/logger';
import { IMessageHandler, PostOffice } from '../../react-common/postOffice';
import { create as createKernel } from './kernel';
Expand All @@ -29,10 +28,11 @@ import { noop } from '../../../../platform/common/utils/misc';
/* eslint-disable @typescript-eslint/no-explicit-any */

export class WidgetManager implements IIPyWidgetManager, IMessageHandler {
public static get instance(): Observable<WidgetManager | undefined> {
return WidgetManager._instance;
public static get onDidChangeInstance(): Event<WidgetManager | undefined> {
return WidgetManager._onDidChangeInstance.event;
}
private static _instance = new ReplaySubject<WidgetManager | undefined>();
private static _onDidChangeInstance = new EventEmitter<WidgetManager | undefined>();
public static instance: WidgetManager | undefined;
private manager?: IJupyterLabWidgetManager;
private proxyKernel?: Kernel.IKernelConnection;
private options?: KernelSocketOptions;
Expand Down Expand Up @@ -105,7 +105,8 @@ export class WidgetManager implements IIPyWidgetManager, IMessageHandler {
this.manager = undefined;
this.proxyKernel?.dispose(); // NOSONAR
this.proxyKernel = undefined;
WidgetManager._instance.next(undefined);
WidgetManager.instance = undefined;
WidgetManager._onDidChangeInstance.fire(undefined);
} else if (!this.proxyKernel) {
logMessage(`Received some pending message ${message}`);
this.pendingMessages.push({ message, payload });
Expand Down Expand Up @@ -237,7 +238,8 @@ export class WidgetManager implements IIPyWidgetManager, IMessageHandler {
this.manager.onUnhandledIOPubMessage.connect(this.handleUnhandledIOPubMessage.bind(this));

// Tell the observable about our new manager
WidgetManager._instance.next(this);
WidgetManager.instance = this;
WidgetManager._onDidChangeInstance.fire(this);
} catch (ex) {
// eslint-disable-next-line no-console
console.error('Failed to initialize WidgetManager', ex);
Expand Down

0 comments on commit a727344

Please sign in to comment.