diff --git a/vscode-trace-extension/src/external-api/external-api.ts b/vscode-trace-extension/src/external-api/external-api.ts index 9278eccf..848c4dfc 100644 --- a/vscode-trace-extension/src/external-api/external-api.ts +++ b/vscode-trace-extension/src/external-api/external-api.ts @@ -8,7 +8,7 @@ import { TraceViewerPanel } from '../trace-viewer-panel/trace-viewer-webview-pan import * as vscode from 'vscode'; import { traceExtensionWebviewManager, traceServerManager } from '../extension'; import { TraceServerContributor } from '../utils/trace-server-manager'; -import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; +import { SignalArgs, signalManager, Signals, SignalType } from 'traceviewer-base/lib/signals/signal-manager'; import { TraceExplorerResourceTypeHandler } from '../utils/trace-explorer-resource-type-handler'; export interface ExternalAPI { @@ -17,8 +17,18 @@ export interface ExternalAPI { getActiveWebviews(): vscode.WebviewView[]; onWebviewCreated(listener: (data: vscode.WebviewView) => void): void; onWebviewPanelCreated(listener: (data: vscode.WebviewPanel) => void): void; - onSignalManagerSignal(event: string | symbol, listener: (...args: unknown[]) => void): void; - offSignalManagerSignal(event: string | symbol, listener: (...args: unknown[]) => void): void; + onSignalManagerSignal( + event: K, + listener: ( + ...args: SignalArgs extends [] ? [] : [...SignalArgs] + ) => void | Promise + ): void; + offSignalManagerSignal( + event: K, + listener: ( + ...args: SignalArgs extends [] ? [] : [...SignalArgs] + ) => void | Promise + ): void; addTraceServerContributor(contributor: TraceServerContributor): void; setHandleTraceResourceType(handleFiles: boolean, handleFolders: boolean): void; } @@ -75,7 +85,12 @@ export const traceExtensionAPI: ExternalAPI = { * @param event event for which a listener should be attached * @param listener event listener */ - onSignalManagerSignal(event: string | symbol, listener: (...args: unknown[]) => void): void { + onSignalManagerSignal( + event: K, + listener: ( + ...args: SignalArgs extends [] ? [] : [...SignalArgs] + ) => void | Promise + ): void { signalManager().on(event, listener); }, @@ -85,7 +100,12 @@ export const traceExtensionAPI: ExternalAPI = { * @param event event for which a listener should be removed * @param listener event listener to remove */ - offSignalManagerSignal(event: string | symbol, listener: (...args: unknown[]) => void): void { + offSignalManagerSignal( + event: K, + listener: ( + ...args: SignalArgs extends [] ? [] : [...SignalArgs] + ) => void | Promise + ): void { signalManager().off(event, listener); }, diff --git a/vscode-trace-extension/src/trace-explorer/available-views/trace-explorer-available-views-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/available-views/trace-explorer-available-views-webview-provider.ts index 5e283cd5..558becc5 100644 --- a/vscode-trace-extension/src/trace-explorer/available-views/trace-explorer-available-views-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/available-views/trace-explorer-available-views-webview-provider.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import JSONBigConfig from 'json-bigint'; -import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager'; +import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; import { Experiment } from 'tsp-typescript-client/lib/models/experiment'; import { OutputDescriptor } from 'tsp-typescript-client/lib/models/output-descriptor'; import * as vscode from 'vscode'; @@ -51,7 +51,7 @@ export class TraceExplorerAvailableViewsProvider extends AbstractTraceExplorerPr data: getTspClientUrl() }); if (this._selectedExperiment !== undefined) { - signalManager().fireExperimentSelectedSignal(this._selectedExperiment); + signalManager().emit('EXPERIMENT_SELECTED', this._selectedExperiment); } return; case VSCODE_MESSAGES.OUTPUT_ADDED: @@ -75,7 +75,7 @@ export class TraceExplorerAvailableViewsProvider extends AbstractTraceExplorerPr } else { this._selectedExperiment = undefined; } - signalManager().fireExperimentSelectedSignal(this._selectedExperiment); + signalManager().emit('EXPERIMENT_SELECTED', this._selectedExperiment); } finally { this._selectionOngoing = false; } @@ -86,11 +86,11 @@ export class TraceExplorerAvailableViewsProvider extends AbstractTraceExplorerPr this._disposables ); - signalManager().on(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); + signalManager().on('EXPERIMENT_SELECTED', this._onExperimentSelected); } protected dispose() { - signalManager().off(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); + signalManager().off('EXPERIMENT_SELECTED', this._onExperimentSelected); super.dispose(); } diff --git a/vscode-trace-extension/src/trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider.ts index 725d5018..36a12923 100644 --- a/vscode-trace-extension/src/trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import JSONBigConfig from 'json-bigint'; -import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager'; +import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; import { Experiment } from 'tsp-typescript-client/lib/models/experiment'; import * as vscode from 'vscode'; import { convertSignalExperiment } from 'vscode-trace-common/lib/signals/vscode-signal-converter'; @@ -51,7 +51,7 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer // Note that the open-traces webview will send experimentSelectedSignal signal to update the // available-views view. If the webview is not visible (e.g. it's minimized) then send the signal // here to update the available-views view. - signalManager().fireExperimentSelectedSignal(this._selectedExperiment); + signalManager().emit('EXPERIMENT_SELECTED', this._selectedExperiment); } } } @@ -87,7 +87,7 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer if (this._selectedExperiment !== undefined) { // tabActivatedSignal will select the experiment in the opened-traces view // which will then update available-views view - signalManager().fireTraceViewerTabActivatedSignal(this._selectedExperiment); + signalManager().emit('TRACEVIEWERTAB_ACTIVATED', this._selectedExperiment); } return; case VSCODE_MESSAGES.RE_OPEN_TRACE: @@ -110,7 +110,7 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer if (data && data.wrapper) { // just remove the panel here TraceViewerPanel.disposePanel(this._extensionUri, JSONBig.parse(data.wrapper).name); - signalManager().fireExperimentSelectedSignal(undefined); + signalManager().emit('EXPERIMENT_SELECTED', undefined); } return; case VSCODE_MESSAGES.OPENED_TRACES_UPDATED: @@ -126,7 +126,7 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer } else { experiment = undefined; } - signalManager().fireExperimentSelectedSignal(experiment); + signalManager().emit('EXPERIMENT_SELECTED', experiment); } } }, @@ -134,14 +134,14 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer this._disposables ); - signalManager().on(Signals.TRACEVIEWERTAB_ACTIVATED, this._onOpenedTracesWidgetActivated); - signalManager().on(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); - signalManager().on(Signals.EXPERIMENT_OPENED, this._onExperimentOpened); + signalManager().on('TRACEVIEWERTAB_ACTIVATED', this._onOpenedTracesWidgetActivated); + signalManager().on('EXPERIMENT_SELECTED', this._onExperimentSelected); + signalManager().on('EXPERIMENT_OPENED', this._onExperimentOpened); } protected dispose() { - signalManager().off(Signals.TRACEVIEWERTAB_ACTIVATED, this._onOpenedTracesWidgetActivated); - signalManager().off(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); - signalManager().off(Signals.EXPERIMENT_OPENED, this._onExperimentOpened); + signalManager().off('TRACEVIEWERTAB_ACTIVATED', this._onOpenedTracesWidgetActivated); + signalManager().off('EXPERIMENT_SELECTED', this._onExperimentSelected); + signalManager().off('EXPERIMENT_OPENED', this._onExperimentOpened); super.dispose(); } } diff --git a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts index 112c0c6d..d9953de4 100644 --- a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts @@ -5,7 +5,7 @@ ***************************************************************************************/ import * as vscode from 'vscode'; import { AbstractTraceExplorerProvider } from '../abstract-trace-explorer-provider'; -import { Signals, signalManager } from 'traceviewer-base/lib/signals/signal-manager'; +import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; import { VSCODE_MESSAGES } from 'vscode-trace-common/lib/messages/vscode-message-manager'; import { Experiment } from 'tsp-typescript-client/lib/models/experiment'; import { ItemPropertiesSignalPayload } from 'traceviewer-base/lib/signals/item-properties-signal-payload'; @@ -33,26 +33,23 @@ export class TraceExplorerItemPropertiesProvider extends AbstractTraceExplorerPr } } }); - signalManager().on(Signals.ITEM_PROPERTIES_UPDATED, this.handleUpdatedProperties); - signalManager().on(Signals.EXPERIMENT_SELECTED, this.handleExperimentChanged); - signalManager().on(Signals.CLOSE_TRACEVIEWERTAB, this.handleTabClosed); + signalManager().on('ITEM_PROPERTIES_UPDATED', this.handleUpdatedProperties); + signalManager().on('EXPERIMENT_SELECTED', this.handleExperimentChanged); + signalManager().on('CLOSE_TRACEVIEWERTAB', this.handleTabClosed); return; } - handleExperimentChanged = (exp: Experiment) => { - const props = this.propertiesMap.get(exp?.UUID); - if (props) { - this.handleUpdatedProperties(props); - } else { - const emptyPayload = new ItemPropertiesSignalPayload({}); - this.handleUpdatedProperties(emptyPayload); - } + handleExperimentChanged = (exp?: Experiment) => { + const payload = exp + ? this.propertiesMap.get(exp.UUID) || new ItemPropertiesSignalPayload({}) + : new ItemPropertiesSignalPayload({}); + this.handleUpdatedProperties(payload); }; protected dispose(): void { - signalManager().off(Signals.ITEM_PROPERTIES_UPDATED, this.handleUpdatedProperties); - signalManager().off(Signals.EXPERIMENT_SELECTED, this.handleExperimentChanged); - signalManager().off(Signals.CLOSE_TRACEVIEWERTAB, this.handleTabClosed); + signalManager().off('ITEM_PROPERTIES_UPDATED', this.handleUpdatedProperties); + signalManager().off('EXPERIMENT_SELECTED', this.handleExperimentChanged); + signalManager().off('CLOSE_TRACEVIEWERTAB', this.handleTabClosed); } handleTabClosed = (expUUID: string) => { diff --git a/vscode-trace-extension/src/trace-explorer/time-range/trace-explorer-time-range-data-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/time-range/trace-explorer-time-range-data-webview-provider.ts index c840fe94..0e4c5f27 100644 --- a/vscode-trace-extension/src/trace-explorer/time-range/trace-explorer-time-range-data-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/time-range/trace-explorer-time-range-data-webview-provider.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; import JSONBigConfig from 'json-bigint'; -import { Signals, signalManager } from 'traceviewer-base/lib/signals/signal-manager'; +import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; import { TimeRangeUpdatePayload } from 'traceviewer-base/lib/signals/time-range-data-signal-payloads'; import { TimeRangeDataMap } from 'traceviewer-react-components/lib/components/utils/time-range-data-map'; import { Experiment } from 'tsp-typescript-client/lib/models/experiment'; @@ -35,7 +35,7 @@ export class TraceExplorerTimeRangeDataProvider extends AbstractTraceExplorerPro switch (command) { case VSCODE_MESSAGES.REQUEST_SELECTION_RANGE_CHANGE: - signalManager().fireRequestSelectionRangeChange(parsedData); + signalManager().emit('REQUEST_SELECTION_RANGE_CHANGE', parsedData); break; } }, @@ -56,21 +56,21 @@ export class TraceExplorerTimeRangeDataProvider extends AbstractTraceExplorerPro } }); - signalManager().on(Signals.VIEW_RANGE_UPDATED, this.onViewRangeUpdated); - signalManager().on(Signals.SELECTION_RANGE_UPDATED, this.onSelectionRangeUpdated); - signalManager().on(Signals.EXPERIMENT_SELECTED, this.onExperimentSelected); - signalManager().on(Signals.EXPERIMENT_UPDATED, this.onExperimentUpdated); - signalManager().on(Signals.EXPERIMENT_CLOSED, this.onExperimentClosed); - signalManager().on(Signals.CLOSE_TRACEVIEWERTAB, this.onExperimentTabClosed); + signalManager().on('VIEW_RANGE_UPDATED', this.onViewRangeUpdated); + signalManager().on('SELECTION_RANGE_UPDATED', this.onSelectionRangeUpdated); + signalManager().on('EXPERIMENT_SELECTED', this.onExperimentSelected); + signalManager().on('EXPERIMENT_UPDATED', this.onExperimentUpdated); + signalManager().on('EXPERIMENT_CLOSED', this.onExperimentClosed); + signalManager().on('CLOSE_TRACEVIEWERTAB', this.onExperimentTabClosed); } protected dispose() { - signalManager().off(Signals.VIEW_RANGE_UPDATED, this.onViewRangeUpdated); - signalManager().off(Signals.SELECTION_RANGE_UPDATED, this.onSelectionRangeUpdated); - signalManager().off(Signals.EXPERIMENT_SELECTED, this.onExperimentSelected); - signalManager().off(Signals.EXPERIMENT_UPDATED, this.onExperimentUpdated); - signalManager().off(Signals.EXPERIMENT_CLOSED, this.onExperimentClosed); - signalManager().off(Signals.CLOSE_TRACEVIEWERTAB, this.onExperimentTabClosed); + signalManager().off('VIEW_RANGE_UPDATED', this.onViewRangeUpdated); + signalManager().off('SELECTION_RANGE_UPDATED', this.onSelectionRangeUpdated); + signalManager().off('EXPERIMENT_SELECTED', this.onExperimentSelected); + signalManager().off('EXPERIMENT_UPDATED', this.onExperimentUpdated); + signalManager().off('EXPERIMENT_CLOSED', this.onExperimentClosed); + signalManager().off('CLOSE_TRACEVIEWERTAB', this.onExperimentTabClosed); super.dispose(); } diff --git a/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts b/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts index 92857785..ac2b2bb8 100644 --- a/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts +++ b/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts @@ -5,7 +5,7 @@ import { getTspClientUrl, getTraceServerUrl } from '../utils/backend-tsp-client- import { TraceServerConnectionStatusService } from '../utils/trace-server-status'; import { OutputDescriptor } from 'tsp-typescript-client/lib/models/output-descriptor'; import { handleStatusMessage, handleRemoveMessage, setStatusFromPanel } from '../common/trace-message'; -import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager'; +import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; import { VSCODE_MESSAGES } from 'vscode-trace-common/lib/messages/vscode-message-manager'; import { MarkerSet } from 'tsp-typescript-client/lib/models/markerset'; import JSONBigConfig from 'json-bigint'; @@ -219,10 +219,10 @@ export class TraceViewerPanel { this.dispose(); TraceViewerPanel.activePanels[name] = undefined; if (traceUUID) { - signalManager().fireCloseTraceViewerTabSignal(traceUUID); + signalManager().emit('CLOSE_TRACEVIEWERTAB', traceUUID); } if (isActivePanel) { - signalManager().fireExperimentSelectedSignal(undefined); + signalManager().emit('EXPERIMENT_SELECTED', undefined); } return this._disposables; }); @@ -234,7 +234,7 @@ export class TraceViewerPanel { if (this._experiment) { // tabActivatedSignal will select the experiment in the opened-traces view // which will then update available-views view - signalManager().fireTraceViewerTabActivatedSignal(this._experiment); + signalManager().emit('TRACEVIEWERTAB_ACTIVATED', this._experiment); } } }); @@ -276,7 +276,8 @@ export class TraceViewerPanel { return; case VSCODE_MESSAGES.UPDATE_PROPERTIES: if (message.data?.properties) { - signalManager().fireItemPropertiesSignalUpdated( + signalManager().emit( + 'ITEM_PROPERTIES_UPDATED', new ItemPropertiesSignalPayload( message.data.properties, message.data.experimentUUID, @@ -328,22 +329,22 @@ export class TraceViewerPanel { } return; case VSCODE_MESSAGES.VIEW_RANGE_UPDATED: - signalManager().fireViewRangeUpdated(JSONBig.parse(message.data)); + signalManager().emit('VIEW_RANGE_UPDATED', JSONBig.parse(message.data)); break; case VSCODE_MESSAGES.SELECTION_RANGE_UPDATED: - signalManager().fireSelectionRangeUpdated(JSONBig.parse(message.data)); + signalManager().emit('SELECTION_RANGE_UPDATED', JSONBig.parse(message.data)); break; case VSCODE_MESSAGES.EXPERIMENT_UPDATED: const experiment = convertSignalExperiment(JSONBig.parse(message.data)); - signalManager().fireExperimentUpdatedSignal(experiment); + signalManager().emit('EXPERIMENT_UPDATED', experiment); break; } }, undefined, this._disposables ); - signalManager().on(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); - signalManager().on(Signals.REQUEST_SELECTION_RANGE_CHANGE, this._onRequestSelectionRangeChange); + signalManager().on('EXPERIMENT_SELECTED', this._onExperimentSelected); + signalManager().on('REQUEST_SELECTION_RANGE_CHANGE', this._onRequestSelectionRangeChange); } public doRefactor(): void { @@ -364,8 +365,8 @@ export class TraceViewerPanel { x.dispose(); } } - signalManager().off(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); - signalManager().off(Signals.REQUEST_SELECTION_RANGE_CHANGE, this._onRequestSelectionRangeChange); + signalManager().off('EXPERIMENT_SELECTED', this._onExperimentSelected); + signalManager().off('REQUEST_SELECTION_RANGE_CHANGE', this._onRequestSelectionRangeChange); } protected doHandleExperimentSelectedSignal(experiment: Experiment | undefined): void { @@ -376,7 +377,7 @@ export class TraceViewerPanel { } protected doHandleExperimentUpdatedSignal(experiment: Experiment): void { - signalManager().fireExperimentUpdatedSignal(experiment); + signalManager().emit('EXPERIMENT_UPDATED', experiment); } protected doHandleRequestSelectionRangeChange(payload: TimeRangeUpdatePayload): void { @@ -389,8 +390,8 @@ export class TraceViewerPanel { this._experiment = experiment; const wrapper: string = JSONBig.stringify(experiment); this._panel.webview.postMessage({ command: VSCODE_MESSAGES.SET_EXPERIMENT, data: wrapper }); - signalManager().fireExperimentOpenedSignal(experiment); - signalManager().fireTraceViewerTabActivatedSignal(experiment); + signalManager().emit('EXPERIMENT_OPENED', experiment); + signalManager().emit('TRACEVIEWERTAB_ACTIVATED', experiment); } addOutput(descriptor: OutputDescriptor): void { diff --git a/vscode-trace-webviews/src/trace-explorer/available-views/vscode-trace-explorer-views-widget.tsx b/vscode-trace-webviews/src/trace-explorer/available-views/vscode-trace-explorer-views-widget.tsx index 4fb99fa1..94a299e3 100644 --- a/vscode-trace-webviews/src/trace-explorer/available-views/vscode-trace-explorer-views-widget.tsx +++ b/vscode-trace-webviews/src/trace-explorer/available-views/vscode-trace-explorer-views-widget.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/ban-types */ import * as React from 'react'; import { OutputAddedSignalPayload } from 'traceviewer-base/lib/signals/output-added-signal-payload'; -import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager'; +import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; import { ReactAvailableViewsWidget } from 'traceviewer-react-components/lib/trace-explorer/trace-explorer-views-widget'; import 'traceviewer-react-components/style/trace-explorer.css'; import { Experiment } from 'tsp-typescript-client/lib/models/experiment'; @@ -49,7 +49,7 @@ class TraceExplorerViewsWidget extends React.Component<{}, AvailableViewsAppStat if (message.data) { experiment = convertSignalExperiment(JSONBig.parse(message.data)); } - signalManager().fireExperimentSelectedSignal(experiment); + signalManager().emit('EXPERIMENT_SELECTED', experiment); break; case VSCODE_MESSAGES.TRACE_SERVER_URL_CHANGED: if (message.data && this.state.tspClientProvider) { @@ -62,13 +62,13 @@ class TraceExplorerViewsWidget extends React.Component<{}, AvailableViewsAppStat componentDidMount(): void { this._signalHandler.notifyReady(); - signalManager().on(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); - signalManager().on(Signals.OUTPUT_ADDED, this._onOutputAdded); + signalManager().on('EXPERIMENT_SELECTED', this._onExperimentSelected); + signalManager().on('OUTPUT_ADDED', this._onOutputAdded); } componentWillUnmount(): void { - signalManager().off(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); - signalManager().off(Signals.OUTPUT_ADDED, this._onOutputAdded); + signalManager().off('EXPERIMENT_SELECTED', this._onExperimentSelected); + signalManager().off('OUTPUT_ADDED', this._onOutputAdded); } protected doHandleExperimentSelectedSignal(experiment: Experiment | undefined): void { diff --git a/vscode-trace-webviews/src/trace-explorer/opened-traces/vscode-trace-explorer-opened-traces-widget.tsx b/vscode-trace-webviews/src/trace-explorer/opened-traces/vscode-trace-explorer-opened-traces-widget.tsx index cb0cb02f..2bca0085 100644 --- a/vscode-trace-webviews/src/trace-explorer/opened-traces/vscode-trace-explorer-opened-traces-widget.tsx +++ b/vscode-trace-webviews/src/trace-explorer/opened-traces/vscode-trace-explorer-opened-traces-widget.tsx @@ -5,7 +5,7 @@ import { VsCodeMessageManager, VSCODE_MESSAGES } from 'vscode-trace-common/lib/m import { Menu, Item, useContextMenu, ItemParams } from 'react-contexify'; import { TspClientProvider } from 'vscode-trace-common/lib/client/tsp-client-provider-impl'; import { Experiment } from 'tsp-typescript-client/lib/models/experiment'; -import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager'; +import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; import '../../style/trace-viewer.css'; import 'traceviewer-react-components/style/trace-explorer.css'; import '../../style/react-contextify.css'; @@ -66,17 +66,17 @@ class TraceExplorerOpenedTraces extends React.Component<{}, OpenedTracesAppState case VSCODE_MESSAGES.TRACE_VIEWER_TAB_ACTIVATED: if (message.data) { const experiment = convertSignalExperiment(JSONBig.parse(message.data)); - signalManager().fireTraceViewerTabActivatedSignal(experiment); + signalManager().emit('TRACEVIEWERTAB_ACTIVATED', experiment); } break; case VSCODE_MESSAGES.EXPERIMENT_OPENED: if (message.data) { const experiment = convertSignalExperiment(JSONBig.parse(message.data)); - signalManager().fireExperimentOpenedSignal(experiment); + signalManager().emit('EXPERIMENT_OPENED', experiment); } break; case VSCODE_MESSAGES.TRACE_SERVER_STARTED: - signalManager().fireTraceServerStartedSignal(); + signalManager().emit('TRACE_SERVER_STARTED'); case VSCODE_MESSAGES.TRACE_SERVER_URL_CHANGED: if (message.data && this.state.tspClientProvider) { this.state.tspClientProvider.updateTspClientUrl(message.data); @@ -91,15 +91,15 @@ class TraceExplorerOpenedTraces extends React.Component<{}, OpenedTracesAppState this._signalHandler.notifyReady(); // ExperimentSelected handler is registered in the constructor (upstream code), but it's // better to register it here when the react component gets mounted. - signalManager().on(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); - signalManager().on(Signals.CLOSE_TRACEVIEWERTAB, this._onRemoveTraceButton); - signalManager().on(Signals.OPENED_TRACES_UPDATED, this.onUpdateSignal); + signalManager().on('EXPERIMENT_SELECTED', this._onExperimentSelected); + signalManager().on('CLOSE_TRACEVIEWERTAB', this._onRemoveTraceButton); + signalManager().on('OPENED_TRACES_UPDATED', this.onUpdateSignal); } componentWillUnmount(): void { - signalManager().off(Signals.EXPERIMENT_SELECTED, this._onExperimentSelected); - signalManager().off(Signals.CLOSE_TRACEVIEWERTAB, this._onRemoveTraceButton); - signalManager().off(Signals.OPENED_TRACES_UPDATED, this.onUpdateSignal); + signalManager().off('EXPERIMENT_SELECTED', this._onExperimentSelected); + signalManager().off('CLOSE_TRACEVIEWERTAB', this._onRemoveTraceButton); + signalManager().off('OPENED_TRACES_UPDATED', this.onUpdateSignal); } private initialized = false; diff --git a/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx b/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx index d7939579..88391562 100644 --- a/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx +++ b/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx @@ -37,7 +37,7 @@ class TraceExplorerProperties extends React.Component<{}, PropertiesViewState> { message.data.experimentUUID, message.data.outputDescriptorId ); - signalManager().fireItemPropertiesSignalUpdated(payload); + signalManager().emit('ITEM_PROPERTIES_UPDATED', payload); } break; } diff --git a/vscode-trace-webviews/src/trace-explorer/time-range/vscode-time-range-data-widget.tsx b/vscode-trace-webviews/src/trace-explorer/time-range/vscode-time-range-data-widget.tsx index 6fd5692e..bcbe9f3a 100644 --- a/vscode-trace-webviews/src/trace-explorer/time-range/vscode-time-range-data-widget.tsx +++ b/vscode-trace-webviews/src/trace-explorer/time-range/vscode-time-range-data-widget.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Signals, signalManager } from 'traceviewer-base/lib/signals/signal-manager'; +import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; import { ExperimentTimeRangeData, ReactTimeRangeDataWidget @@ -43,31 +43,32 @@ class TimeRangeDataWidget extends React.Component { this.restoreState(mapArray, activeData); return; case VSCODE_MESSAGES.TRACE_VIEWER_TAB_CLOSED: - signalManager().fireCloseTraceViewerTabSignal(data); + signalManager().emit('CLOSE_TRACEVIEWERTAB', data); break; case VSCODE_MESSAGES.EXPERIMENT_SELECTED: - signalManager().fireExperimentSelectedSignal( + signalManager().emit( + 'EXPERIMENT_SELECTED', data?.wrapper ? convertSignalExperiment(JSONBig.parse(data.wrapper)) : undefined ); break; case VSCODE_MESSAGES.EXPERIMENT_UPDATED: - signalManager().fireExperimentUpdatedSignal(convertSignalExperiment(JSONBig.parse(data.wrapper))); + signalManager().emit('EXPERIMENT_UPDATED', convertSignalExperiment(JSONBig.parse(data.wrapper))); break; case VSCODE_MESSAGES.EXPERIMENT_CLOSED: - signalManager().fireExperimentClosedSignal(convertSignalExperiment(JSONBig.parse(data.wrapper))); + signalManager().emit('EXPERIMENT_CLOSED', convertSignalExperiment(JSONBig.parse(data.wrapper))); break; case VSCODE_MESSAGES.SELECTION_RANGE_UPDATED: - signalManager().fireSelectionRangeUpdated(JSONBig.parse(data)); + signalManager().emit('SELECTION_RANGE_UPDATED', JSONBig.parse(data)); break; case VSCODE_MESSAGES.VIEW_RANGE_UPDATED: - signalManager().fireViewRangeUpdated(JSONBig.parse(data)); + signalManager().emit('VIEW_RANGE_UPDATED', JSONBig.parse(data)); break; } }); } componentWillUnmount = (): void => { - signalManager().off(Signals.REQUEST_SELECTION_RANGE_CHANGE, this.onRequestSelectionChange); + signalManager().off('REQUEST_SELECTION_RANGE_CHANGE', this.onRequestSelectionChange); }; onRequestSelectionChange = (payload: TimeRangeUpdatePayload): void => { @@ -76,7 +77,7 @@ class TimeRangeDataWidget extends React.Component { componentDidMount = (): void => { this._signalHandler.notifyReady(); - signalManager().on(Signals.REQUEST_SELECTION_RANGE_CHANGE, this.onRequestSelectionChange); + signalManager().on('REQUEST_SELECTION_RANGE_CHANGE', this.onRequestSelectionChange); }; restoreState = (mapArray: Array, activeData: ExperimentTimeRangeData): void => { diff --git a/vscode-trace-webviews/src/trace-viewer/vscode-trace-viewer-container.tsx b/vscode-trace-webviews/src/trace-viewer/vscode-trace-viewer-container.tsx index 463b1b36..9a2d02ec 100644 --- a/vscode-trace-webviews/src/trace-viewer/vscode-trace-viewer-container.tsx +++ b/vscode-trace-webviews/src/trace-viewer/vscode-trace-viewer-container.tsx @@ -6,7 +6,7 @@ import JSONBigConfig from 'json-bigint'; import * as React from 'react'; import 'react-grid-layout/css/styles.css'; import 'react-resizable/css/styles.css'; -import { signalManager, Signals } from 'traceviewer-base/lib/signals/signal-manager'; +import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; import { ContextMenuItems, ContextMenuContributedSignalPayload @@ -53,7 +53,7 @@ class TraceViewerContainer extends React.Component<{}, VscodeAppState> { private _onProperties = (properties: ItemPropertiesSignalPayload): void => this.doHandlePropertiesSignal(properties); - private _onSaveAsCSV = (payload: { traceId: string; data: string }): void => this.doHandleSaveAsCSVSignal(payload); + private _onSaveAsCSV = (traceId: string, data: string): void => this.doHandleSaveAsCSVSignal(traceId, data); private _onRowSelectionChanged = (payload: RowSelectionsChangedSignalPayload): void => this.doHandleRowSelectSignal(payload); private _onContextMenuItemClicked = (payload: ContextMenuItemClickedSignalPayload): void => @@ -64,8 +64,8 @@ class TraceViewerContainer extends React.Component<{}, VscodeAppState> { this._signalHandler.propertiesUpdated(properties); } - private doHandleSaveAsCSVSignal(payload: { traceId: string; data: string }) { - this._signalHandler.saveAsCSV(payload); + private doHandleSaveAsCSVSignal(traceId: string, data: string) { + this._signalHandler.saveAsCSV({ traceId, data }); } private doHandleRowSelectSignal(payload: RowSelectionsChangedSignalPayload) { @@ -76,10 +76,10 @@ class TraceViewerContainer extends React.Component<{}, VscodeAppState> { this._signalHandler.contextMenuItemClicked(payload); } - private _onOverviewSelected = (payload: { traceId: string; outputDescriptor: OutputDescriptor }): void => - this.doHandleOverviewSelectedSignal(payload); - private onMarkerCategoryClosedSignal = (payload: { traceViewerId: string; markerCategory: string }) => - this.doHandleMarkerCategoryClosedSignal(payload); + private _onOverviewSelected = (traceId: string, outputDescriptor: OutputDescriptor): void => + this.doHandleOverviewSelectedSignal(traceId, outputDescriptor); + private onMarkerCategoryClosedSignal = (traceViewerId: string, markerCategory: string) => + this.doHandleMarkerCategoryClosedSignal(traceViewerId, markerCategory); protected resizeHandlers: (() => void)[] = []; protected readonly addResizeHandler = (h: () => void): void => { @@ -163,10 +163,10 @@ class TraceViewerContainer extends React.Component<{}, VscodeAppState> { case VSCODE_MESSAGES.UPDATE_ZOOM: this.updateZoom(message.data); case VSCODE_MESSAGES.VIEW_RANGE_UPDATED: - signalManager().fireViewRangeUpdated(JSONBig.parse(message.data)); + signalManager().emit('VIEW_RANGE_UPDATED', JSONBig.parse(message.data)); break; case VSCODE_MESSAGES.SELECTION_RANGE_UPDATED: - signalManager().fireSelectionRangeUpdated(JSONBig.parse(message.data)); + signalManager().emit('SELECTION_RANGE_UPDATED', JSONBig.parse(message.data)); break; case VSCODE_MESSAGES.REQUEST_SELECTION_RANGE_CHANGE: const { experimentUUID, timeRange } = JSONBig.parse(message.data); @@ -174,7 +174,7 @@ class TraceViewerContainer extends React.Component<{}, VscodeAppState> { experimentUUID, timeRange: new TimeRange(BigInt(timeRange.start), BigInt(timeRange.end)) } as TimeRangeUpdatePayload; - signalManager().fireRequestSelectionRangeChange(payload); + signalManager().emit('REQUEST_SELECTION_RANGE_CHANGE', payload); break; case VSCODE_MESSAGES.UPDATE_MARKER_CATEGORY_STATE: if (message?.data) { @@ -221,31 +221,31 @@ class TraceViewerContainer extends React.Component<{}, VscodeAppState> { window.addEventListener('resize', this.onResize); this.onOutputRemoved = this.onOutputRemoved.bind(this); this.onOverviewRemoved = this.onOverviewRemoved.bind(this); - signalManager().on(Signals.OVERVIEW_OUTPUT_SELECTED, this._onOverviewSelected); + signalManager().on('OVERVIEW_OUTPUT_SELECTED', this._onOverviewSelected); } componentDidMount(): void { this._signalHandler.notifyReady(); - signalManager().on(Signals.CONTEXT_MENU_ITEM_CLICKED, this._onContextMenuItemClicked); - signalManager().on(Signals.ROW_SELECTIONS_CHANGED, this._onRowSelectionChanged); - signalManager().on(Signals.ITEM_PROPERTIES_UPDATED, this._onProperties); - signalManager().on(Signals.SAVE_AS_CSV, this._onSaveAsCSV); - signalManager().on(Signals.MARKER_CATEGORY_CLOSED, this.onMarkerCategoryClosedSignal); - signalManager().on(Signals.VIEW_RANGE_UPDATED, this.onViewRangeUpdated); - signalManager().on(Signals.SELECTION_RANGE_UPDATED, this.onSelectionRangeUpdated); - signalManager().on(Signals.EXPERIMENT_UPDATED, this.onExperimentUpdated); + signalManager().on('CONTEXT_MENU_ITEM_CLICKED', this._onContextMenuItemClicked); + signalManager().on('ROW_SELECTIONS_CHANGED', this._onRowSelectionChanged); + signalManager().on('ITEM_PROPERTIES_UPDATED', this._onProperties); + signalManager().on('SAVE_AS_CSV', this._onSaveAsCSV); + signalManager().on('MARKER_CATEGORY_CLOSED', this.onMarkerCategoryClosedSignal); + signalManager().on('VIEW_RANGE_UPDATED', this.onViewRangeUpdated); + signalManager().on('SELECTION_RANGE_UPDATED', this.onSelectionRangeUpdated); + signalManager().on('EXPERIMENT_UPDATED', this.onExperimentUpdated); } componentWillUnmount(): void { - signalManager().off(Signals.CONTEXT_MENU_ITEM_CLICKED, this._onContextMenuItemClicked); - signalManager().off(Signals.ROW_SELECTIONS_CHANGED, this._onRowSelectionChanged); - signalManager().off(Signals.ITEM_PROPERTIES_UPDATED, this._onProperties); - signalManager().off(Signals.OVERVIEW_OUTPUT_SELECTED, this._onOverviewSelected); - signalManager().off(Signals.SAVE_AS_CSV, this._onSaveAsCSV); - signalManager().off(Signals.MARKER_CATEGORY_CLOSED, this.onMarkerCategoryClosedSignal); - signalManager().off(Signals.VIEW_RANGE_UPDATED, this.onViewRangeUpdated); - signalManager().off(Signals.SELECTION_RANGE_UPDATED, this.onSelectionRangeUpdated); - signalManager().off(Signals.EXPERIMENT_UPDATED, this.onExperimentUpdated); + signalManager().off('CONTEXT_MENU_ITEM_CLICKED', this._onContextMenuItemClicked); + signalManager().off('ROW_SELECTIONS_CHANGED', this._onRowSelectionChanged); + signalManager().off('ITEM_PROPERTIES_UPDATED', this._onProperties); + signalManager().off('OVERVIEW_OUTPUT_SELECTED', this._onOverviewSelected); + signalManager().off('SAVE_AS_CSV', this._onSaveAsCSV); + signalManager().off('MARKER_CATEGORY_CLOSED', this.onMarkerCategoryClosedSignal); + signalManager().off('VIEW_RANGE_UPDATED', this.onViewRangeUpdated); + signalManager().off('SELECTION_RANGE_UPDATED', this.onSelectionRangeUpdated); + signalManager().off('EXPERIMENT_UPDATED', this.onExperimentUpdated); window.removeEventListener('resize', this.onResize); } @@ -264,27 +264,27 @@ class TraceViewerContainer extends React.Component<{}, VscodeAppState> { } protected resetZoom(): void { - signalManager().fireResetZoomSignal(); + signalManager().emit('RESET_ZOOM'); } protected undo(): void { - signalManager().fireUndoSignal(); + signalManager().emit('UNDO'); } protected redo(): void { - signalManager().fireRedoSignal(); + signalManager().emit('REDO'); } protected contributeContextMenu(payload: ContextMenuContributedSignalPayload): void { - signalManager().fireContributeContextMenu(payload); + signalManager().emit('CONTRIBUTE_CONTEXT_MENU', payload); } protected doHandleOutputDataChanged(descriptors: OutputDescriptor[]): void { - signalManager().fireOutputDataChanged(descriptors); + signalManager().emit('OUTPUT_DATA_CHANGED', descriptors); } protected updateZoom(hasZoomedIn: boolean): void { - signalManager().fireUpdateZoomSignal(hasZoomedIn); + signalManager().emit('UPDATE_ZOOM', hasZoomedIn); } protected async doHandleExperimentSetSignal( @@ -390,9 +390,7 @@ class TraceViewerContainer extends React.Component<{}, VscodeAppState> { this._signalHandler.setMarkerCategoriesContext(this.toolbarMarkerCategoriesMap.size > 0); } - private doHandleMarkerCategoryClosedSignal(payload: { traceViewerId: string; markerCategory: string }) { - const traceViewerId = payload.traceViewerId; - const markerCategory = payload.markerCategory; + private doHandleMarkerCategoryClosedSignal(traceViewerId: string, markerCategory: string) { if (traceViewerId === this.state.experiment?.UUID) { this.updateMarkerCategoryState(markerCategory, false); } @@ -456,20 +454,15 @@ class TraceViewerContainer extends React.Component<{}, VscodeAppState> { } } - protected doHandleOverviewSelectedSignal(payload: { traceId: string; outputDescriptor: OutputDescriptor }): void { - if ( - this.state.experiment && - payload && - payload?.traceId === this.state.experiment.UUID && - payload.outputDescriptor - ) { - this.setState({ overviewOutputDescriptor: payload.outputDescriptor }); + protected doHandleOverviewSelectedSignal(traceId: string, outputDescriptor: OutputDescriptor): void { + if (this.state.experiment && traceId === this.state.experiment.UUID && outputDescriptor) { + this.setState({ overviewOutputDescriptor: outputDescriptor }); } } protected doHandleThemeChanged(theme: string): void { this.setState({ theme }, () => { - signalManager().fireThemeChangedSignal(theme); + signalManager().emit('THEME_CHANGED', theme); }); }