|
|
@@ -11,11 +11,11 @@ A statum frame consists of a JSON object with three keys:
|
|
|
|
|
|
- `key`: a server issued ID for the slot.
|
|
|
- `scope`: a string value that can be one of:
|
|
|
- - `"device"`: persists between browser sessions.
|
|
|
- - `"session"`: persists within the browser session (e.g. between tabs).
|
|
|
- - `"flow"`: persists only within the current tab, while the tab remains on the site (e.g. persists between navigations).
|
|
|
- - `"page"`: persists only while the current page is loaded (e.g. clears on navigate).
|
|
|
- - `"transient"`: does not persist, will never get sent back to the server - random or `null` key each time.
|
|
|
+ - `"device"`: persists between browser sessions. Backed by `localStorage`.
|
|
|
+ - `"session"`: persists within the browser session (e.g. between tabs). Backed by `localStorage`, kept consistent across tabs via `BroadcastChannel`, and cleared on browser close via a session-cookie marker (see [Initialization](#initialization)).
|
|
|
+ - `"flow"`: persists only within the current tab, while the tab remains on the site (e.g. persists between navigations). Backed by `sessionStorage` (per-tab, survives navigation, cleared when the tab closes).
|
|
|
+ - `"page"`: persists only while the current page is loaded (e.g. clears on navigate). Held in memory.
|
|
|
+ - `"transient"`: does not persist, will never get sent back to the server - random or `null` key each time. Held in memory.
|
|
|
- `type`: an application defined type name.
|
|
|
|
|
|
## Statum Snapshot
|
|
|
@@ -117,6 +117,17 @@ The Javascript API provides access to the state and actions via the global `stat
|
|
|
|
|
|
State is exposed to the application keyed by **slot type**. Statum assumes at most one slot per type, so each type name maps to a single current snapshot; the slot's `key` is used only on the wire (in headers and directives).
|
|
|
|
|
|
+## Initialization
|
|
|
+
|
|
|
+On startup, before fetching the entrypoint or evaluating any bindings, the library checks for a `_statum_sdc` session cookie:
|
|
|
+
|
|
|
+1. If the cookie is absent, this is a fresh browser session: clear all `"session"`-scoped slots from `localStorage`, then set `_statum_sdc=1` (a session cookie, so the browser drops it on close).
|
|
|
+2. If the cookie is present, the browser session is already underway; do nothing.
|
|
|
+
|
|
|
+Because session cookies are shared across all tabs of a browser session, a tab opened mid-session sees the marker the first tab set and does not wipe session data. This step must run before anything else so stale session state is never read or sent.
|
|
|
+
|
|
|
+Caveats: browsers with a "continue/restore session" feature preserve session cookies across restarts, so in that mode stale session data may not be cleared on reopen; and if cookies are blocked entirely, `"session"` scope degrades to per-page-load.
|
|
|
+
|
|
|
## Managing State
|
|
|
|
|
|
State snapshots can be cleaned up via `statum.clear("typeName")`. All snapshots can be cleared via `statum.clear()`.
|