feat: Absturzschutz fuer die laufende Sitzung

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
vchuser
2026-07-28 15:57:28 +02:00
co-authored by Claude Opus 5
parent 37df87a324
commit 4d896702d1
2 changed files with 90 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
// Reines Modul: kein window, kein document, kein localStorage.
const KEY = 'ram-sortierhilfe:session';
/**
* Absturzschutz, keine Bestandsfuehrung: die laufende Sitzung wird
* gesichert, damit ein versehentliches Neuladen sie nicht vernichtet.
*/
export function saveSession(session, store) {
try {
store.setItem(KEY, JSON.stringify(session));
} catch {
// Voller oder gesperrter Speicher darf das Sortieren nicht unterbrechen.
}
}
/** @returns {object|null} */
export function loadSession(store) {
try {
const raw = store.getItem(KEY);
if (!raw) return null;
const parsed = JSON.parse(raw);
if (!Array.isArray(parsed.stacks) || !Array.isArray(parsed.entries)) return null;
return parsed;
} catch {
return null;
}
}
export function clearSession(store) {
try {
store.removeItem(KEY);
} catch {
// siehe oben
}
}