# core/stores/route.store.ts

> 22 lines of code and 4 definitions.

Tree: Site tree
Language: typescript
Layer: application
Canonical: https://banes-lab.com/anatomy/tree#file-core-stores-route-store-ts
Source text: https://banes-lab.com/assets/sources/source.ef5ae1866ca7eaced4768d4d6ca50505405b431c2047b758c0c2ea6bdf98b9dc.generated.txt

## Definitions

- `writeScroll` (lexical_declaration, line 16, exported)
- `readScroll` (lexical_declaration, line 5, exported)
- `stored` (lexical_declaration, line 7, exported)
- `top` (lexical_declaration, line 8, exported)

## Uses

- [core/reporters/failure.reporter.ts](https://banes-lab.com/source/tree/core/reporters/failure.reporter.ts.md)

## Used by

- [runtime/coordinators/route.coordinator.ts](https://banes-lab.com/source/tree/runtime/coordinators/route.coordinator.ts.md)

## Source

```typescript
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;
    }
};
```
