jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
This commit is contained in:
@@ -12,9 +12,16 @@ import { state } from './state.mjs';
|
||||
import { banner, hideBanner, renderMeter, setWho, setSessionInfo } from './chrome.mjs';
|
||||
import { logEvent } from './log.mjs';
|
||||
|
||||
/** One registered view: its pane element id, its enter (arg = the
|
||||
* path-captured run id), and its optional leave. */
|
||||
/** @typedef {{ el: string, enter: (arg: ?string, seq: number) => void|Promise<void>, leave?: () => void }} ViewDef */
|
||||
|
||||
/** @type {Record<string, ViewDef>} */
|
||||
const views = {};
|
||||
/** @param {Record<string, ViewDef>} map */
|
||||
export function registerViews(map) { Object.assign(views, map); }
|
||||
|
||||
/** @param {string} p */
|
||||
export function navigate(p) {
|
||||
history.pushState({}, '', p);
|
||||
render();
|
||||
@@ -22,11 +29,14 @@ export function navigate(p) {
|
||||
|
||||
window.addEventListener('popstate', () => render());
|
||||
|
||||
/** @returns {Promise<void>} */
|
||||
export async function render() {
|
||||
const seq = ++state.seq;
|
||||
hideBanner();
|
||||
const p = location.pathname;
|
||||
/** @type {?string} */
|
||||
let name = null;
|
||||
/** @type {?string} */
|
||||
let arg = null;
|
||||
let m;
|
||||
if (p === '/') name = 'home';
|
||||
@@ -35,10 +45,12 @@ export async function render() {
|
||||
else if ((m = p.match(/^\/runs\/([a-z0-9-]+)\/story$/))) { name = 'story'; arg = m[1]; }
|
||||
else if ((m = p.match(/^\/runs\/([a-z0-9-]+)$/))) { name = 'play'; arg = m[1]; }
|
||||
else return navigate('/');
|
||||
if (!name) return; // unreachable: the routing always names a view or navigates home
|
||||
if (!state.me) name = 'claim'; // signed out: every path leads to the claim
|
||||
await show(name, arg, seq);
|
||||
}
|
||||
|
||||
/** @param {string} name @param {?string} arg @param {number} seq @returns {Promise<void>} */
|
||||
async function show(name, arg, seq) {
|
||||
const prev = state.view;
|
||||
if (prev && prev !== name && views[prev].leave) views[prev].leave();
|
||||
@@ -53,6 +65,7 @@ async function show(name, arg, seq) {
|
||||
|
||||
// a run that vanished under us (deleted, 404): leave loudly for home.
|
||||
// render() clears the banner first -- set it after the navigate.
|
||||
/** @param {string} id @param {string} from */
|
||||
export function runGone(id, from) {
|
||||
navigate('/');
|
||||
banner(`run ${id} is gone -- deleted?`);
|
||||
|
||||
Reference in New Issue
Block a user