Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970/** * "Where is this?" — the one thing the player bar asks of the song list. * * The bar names the track you can hear; the list is where a track has a row, a cursor, * and a place in the record it came from. Clicking a name in the bar is the reader asking * the list to put that thing under the eye and under the cursor, and the two components * are siblings under the router with no channel between them — so the request goes * through here, the same way the queue and the favorites do. * * What travels is a *kind* and an id rather than a row index, because only the list knows * how rows are keyed and ordered (`buildRows` is its business, not this module's) and a * scroll asked for by index would land on whatever the harvest had rebuilt in the * meantime. The kinds are the three the list has rows for — the bar's title, record and * artist lines each ask for their own. * * There is no answer in this store on purpose: whether the request found a row is * something only the list knows, and it is the list that owns the toolbar line reporting * it (`components/LibraryView.tsx`). This module's job ends at the ask. */import { createSignal } from "solid-js";
/** The three things the list has a row for, and the bar a line of. */export type LocateKind = "track" | "album" | "artist";
export interface LocateRequest { kind: LocateKind; id: string; /** What the bar had printed where the click landed, so the list can name the thing it * could not find rather than reciting an id back at the reader. */ label: string; /** Bumped by every ask: clicking the same name twice has to travel again, and a signal * still holding the identical request would not say anything had happened — the same * reason the list's own scroll carries a nonce. */ n: number;}
export interface LocateStore { /** The most recent request, or null if nobody has asked yet. */ request(): LocateRequest | null; /** * Ask the list to focus one thing. Called from a click handler, which is also why it * takes no signal to read: the bar already has the song in hand. */ ask(kind: LocateKind, id: string, label: string): void;}
/** * The testable factory. Built eagerly at module scope for the shared instance below, for * the reason `createFavoritesStore`'s is: created lazily behind an accessor, its signal * would belong to whichever component happened to read it first, and a route change could * dispose the very request the other component is waiting on. */export function createLocateStore(): LocateStore { const [request, setRequest] = createSignal<LocateRequest | null>(null, { name: "locate-request", }); let asked = 0; return { request, ask: (kind, id, label) => setRequest({ kind, id, label, n: ++asked }), };}
const instance = createLocateStore();
/** The one request line the bar and the list share. */export function locate(): LocateStore { return instance;}