Files
options-pricer/frontend/assets/viewstate-store.js

29 lines
850 B
JavaScript
Raw Normal View History

/**
* Per-page view-state persistence survives navigation within the app.
* Exposed as window.ViewState. No modules, no deps.
*
* Each page stores its last-loaded inputs + data under
* localStorage["optionsPricer:view:<page>"] so navigating away and back
* restores the page exactly as it was.
*/
(function () {
"use strict";
const PREFIX = "optionsPricer:view:";
window.ViewState = {
PREFIX,
load(page) {
try {
const raw = localStorage.getItem(PREFIX + page);
return raw ? JSON.parse(raw) : null;
} catch { return null; }
},
save(page, data) {
try { localStorage.setItem(PREFIX + page, JSON.stringify(data)); }
catch (e) { console.warn("[ViewState] save failed:", e); }
},
clear(page) {
try { localStorage.removeItem(PREFIX + page); } catch {}
},
};
})();