Skip to content

Commit

Permalink
Simplified to using command instead of events (#116-4)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Sep 9, 2024
1 parent cc749af commit 5b553b3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 42 deletions.
18 changes: 0 additions & 18 deletions src/controllers/ExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ export class ExtensionController implements Disposable {
this._outputChannel,
this._toaster
);
this._dhcServiceFactory.onCreated(
this.onDhServiceCreated,
undefined,
this._context.subscriptions
);

this._serverManager = new ServerManager(
this._config,
Expand Down Expand Up @@ -458,19 +453,6 @@ export class ExtensionController implements Disposable {
this._serverManager?.setEditorConnection(editor, dhService);
};

/**
* Handle when a new Deephaven service is created.
* @param dhService The Deephaven service that was created.
* @returns void
*/
onDhServiceCreated = (dhService: IDhService): void => {
dhService.onRequestVariablePanels(
variables => this.onOpenVariablePanels(dhService.serverUrl, variables),
undefined,
this._context.subscriptions
);
};

/**
* Disconnect editor from active connections.
* @param uri
Expand Down
16 changes: 7 additions & 9 deletions src/services/DhService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
NoConsoleTypesError,
parseServerError,
} from '../util';
import { VARIABLE_UNICODE_ICONS } from '../common';
import { OPEN_VARIABLE_PANELS_CMD, VARIABLE_UNICODE_ICONS } from '../common';

const logger = new Logger('DhService');

Expand All @@ -38,11 +38,6 @@ export abstract class DhService<TDH = unknown, TClient = unknown>
private readonly _onDidDisconnect = new vscode.EventEmitter<URL>();
readonly onDidDisconnect = this._onDidDisconnect.event;

public readonly _onRequestVariablePanels = new vscode.EventEmitter<
VariableDefintion[]
>();
readonly onRequestVariablePanels = this._onRequestVariablePanels.event;

public readonly serverUrl: URL;
protected readonly subscriptions: (() => void)[] = [];

Expand Down Expand Up @@ -88,7 +83,6 @@ export abstract class DhService<TDH = unknown, TClient = unknown>
public async dispose(): Promise<void> {
this.clearCaches();
this._onDidDisconnect.dispose();
this._onRequestVariablePanels.dispose();
}

protected getToastErrorMessage(
Expand Down Expand Up @@ -301,8 +295,12 @@ export abstract class DhService<TDH = unknown, TClient = unknown>
this.outputChannel.appendLine(`${icon} ${title}`);
});

this._onRequestVariablePanels.fire(
changed.filter(v => !v.title.startsWith('_'))
const showVariables = changed.filter(v => !v.title.startsWith('_'));

vscode.commands.executeCommand(
OPEN_VARIABLE_PANELS_CMD,
this.serverUrl,
showVariables
);
}

Expand Down
9 changes: 0 additions & 9 deletions src/services/DhcServiceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ export class DhcServiceFactory implements IDhServiceFactory {
private toaster: IToastService
) {}

dispose = async (): Promise<void> => {
this._onCreated.dispose();
};

private _onCreated = new vscode.EventEmitter<DhcService>();
readonly onCreated = this._onCreated.event;

create = (serverUrl: URL, psk?: string): DhcService => {
const dhService = new DhcService(
serverUrl,
Expand All @@ -31,8 +24,6 @@ export class DhcServiceFactory implements IDhServiceFactory {
dhService.setPsk(psk);
}

this._onCreated.fire(dhService);

return dhService;
};
}
10 changes: 4 additions & 6 deletions src/types/serviceTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export interface IDhService<TDH = unknown, TClient = unknown>
readonly isInitialized: boolean;
readonly isConnected: boolean;
readonly onDidDisconnect: vscode.Event<URL>;
readonly onRequestVariablePanels: vscode.Event<VariableDefintion[]>;

initDh: () => Promise<boolean>;

Expand Down Expand Up @@ -61,11 +60,10 @@ export interface IFactory<T, TArgs extends unknown[] = []> {
/**
* Factory for creating IDhService instances.
*/
export interface IDhServiceFactory
extends IFactory<IDhService, [serverUrl: URL, psk?: string]>,
Disposable {
readonly onCreated: vscode.Event<IDhService>;
}
export type IDhServiceFactory = IFactory<
IDhService,
[serverUrl: URL, psk?: string]
>;

export interface IPanelService extends Disposable {
getPanelOrThrow: (url: URL, variableId: VariableID) => vscode.WebviewPanel;
Expand Down

0 comments on commit 5b553b3

Please sign in to comment.