Files
Netcatty/application/state/scriptRunsStore.ts
T
bincxz da831c053f perf(terminal): harden store isolation after multi-agent review
Address correctness and residual jank found in review:

- Expand pane session equality for connect/startup fields (pendingInitialCwd,
  startupCommand, pending scripts, serial/local shell, etc.).
- Cache coding-CLI provider in the signal controller so memo-skipped
  TerminalLayer renders cannot clear titles via a stale sessionsRef.
- Heal terminalCwdStore drift when the renderer ref already has the path.
- Publish shell history synchronously on write/load and via useLayoutEffect.
- Move script runs to scriptRunsStore; Scripts slot subscribes so automation
  ticks no longer re-render TerminalLayerInner.
- TerminalLayerView equal uses stable side-panel keys only (cwd/theme live
  via sidePanelLiveStore, not chrome re-renders).
- Compare terminalFontFamilyId / session log props; stabilize HostTreeView
  callbacks and end-session-drag handler.
2026-07-30 16:32:42 +08:00

44 lines
1.2 KiB
TypeScript

import type { ScriptRun } from '@/types/global/netcatty-bridge-script.d.ts';
type Listener = () => void;
/**
* External store for script automation runs so Scripts side panel can update
* without forcing TerminalLayerInner re-renders on every log/status tick.
*/
class ScriptRunsStore {
private snapshot: readonly ScriptRun[] = [];
private listeners = new Set<Listener>();
getSnapshot = (): readonly ScriptRun[] => this.snapshot;
subscribe = (listener: Listener): (() => void) => {
this.listeners.add(listener);
return () => {
this.listeners.delete(listener);
};
};
setSnapshot(next: readonly ScriptRun[]): void {
if (this.snapshot === next) return;
this.snapshot = next;
for (const listener of this.listeners) {
listener();
}
}
}
export const scriptRunsStore = new ScriptRunsStore();
export function publishScriptRunsSnapshot(runs: readonly ScriptRun[]): void {
scriptRunsStore.setSnapshot(runs);
}
export function getScriptRunsSnapshot(): readonly ScriptRun[] {
return scriptRunsStore.getSnapshot();
}
export function subscribeScriptRuns(listener: Listener): () => void {
return scriptRunsStore.subscribe(listener);
}