From f25b3c82cd9e8dba8820f1c7b96ba9fa5ecc2686 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Mon, 8 Jun 2026 20:28:50 +0530 Subject: [PATCH] refactor: De-duplicate mode routing and drop dead getStateString Code-review cleanup: - Collapse the two mode switches (the historyState.entries getter and activeSlot) into a single slotFor(mode) helper; entries now reads `slotFor(mode)?.value ?? loader`. - Remove the now-unused getStateString export from state.ts (its only consumer was rewritten off it in this PR). Co-Authored-By: Claude Opus 4.8 (1M context) --- .../components/History/historyState.svelte.ts | 45 ++++++++----------- src/lib/util/state.ts | 4 -- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/lib/components/History/historyState.svelte.ts b/src/lib/components/History/historyState.svelte.ts index 36faccd9..72a35b45 100644 --- a/src/lib/components/History/historyState.svelte.ts +++ b/src/lib/components/History/historyState.svelte.ts @@ -56,19 +56,24 @@ if (mode.value === 'loader') { mode.value = 'manual'; } +// The persisted slot backing a mode; loader is in-memory and has no slot. +const slotFor = (m: HistoryType): Persisted | null => { + switch (m) { + case 'auto': { + return auto; + } + case 'manual': { + return manual; + } + default: { + return null; + } + } +}; + export const historyState = { get entries(): HistoryEntry[] { - switch (mode.value) { - case 'auto': { - return auto.value; - } - case 'loader': { - return loader; - } - default: { - return manual.value; - } - } + return slotFor(mode.value)?.value ?? loader; }, get loaderEntries(): HistoryEntry[] { return loader; @@ -125,22 +130,8 @@ export const setLoaderEntries = (entries: Optional[]): void ); }; -const activeSlot = (): Persisted | null => { - switch (mode.value) { - case 'auto': { - return auto; - } - case 'manual': { - return manual; - } - default: { - return null; - } - } -}; - export const removeEntry = (id: string): void => { - const slot = activeSlot(); + const slot = slotFor(mode.value); if (!slot) { return; } @@ -149,7 +140,7 @@ export const removeEntry = (id: string): void => { }; export const clearActive = (): void => { - const slot = activeSlot(); + const slot = slotFor(mode.value); if (!slot) { return; } diff --git a/src/lib/util/state.ts b/src/lib/util/state.ts index e87c9677..811927aa 100644 --- a/src/lib/util/state.ts +++ b/src/lib/util/state.ts @@ -317,10 +317,6 @@ export const initURLSubscription = (): void => { }); }; -export const getStateString = (): string => { - return JSON.stringify(get(inputStateStore)); -}; - export const verifyState = (): void => { const state = get(inputStateStore); if (!state.panZoom) {