core/stores/route.store.ts
core/stores/route.store.ts is a file in Bane's Lab Site. 22 lines of code and 4 definitions.
import { SCROLL_UNREADABLE, SCROLL_UNWRITABLE } from "#configuration/strings/report.strings";
import { SCROLL_STORE_PREFIX } from "#core/ids/route.ids";
import { reportFailure } from "#core/reporters/failure.reporter";
export const readScroll = function readScroll(path: string): number | null {
try {
const stored = window.sessionStorage.getItem(SCROLL_STORE_PREFIX + path);
const top = stored === null ? Number.NaN : Number(stored);
return Number.isFinite(top) && top > 0 ? top : null;
} catch (error) {
reportFailure(SCROLL_UNREADABLE, error);
return null;
}
};
export const writeScroll = function writeScroll(path: string, top: number): boolean {
try {
window.sessionStorage.setItem(SCROLL_STORE_PREFIX + path, String(Math.round(top)));
return true;
} catch (error) {
reportFailure(SCROLL_UNWRITABLE, error);
return false;
}
};