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) <noreply@anthropic.com>
This commit is contained in:
Sidharth Vinod
2026-06-08 20:28:50 +05:30
co-authored by Claude Opus 4.8
parent 2db9355b7b
commit f25b3c82cd
2 changed files with 18 additions and 31 deletions
@@ -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<HistoryEntry[]> | 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<HistoryEntry, 'id'>[]): void
);
};
const activeSlot = (): Persisted<HistoryEntry[]> | 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;
}
-4
View File
@@ -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) {