Blog · Frontend · · 3 min read
The DOM is the state store
In Ptree, the authored HTML controls, <data> elements, aria-* attributes, and :checked states are the state store and the registry. JavaScript reads from them, writes a few custom properties in place, and never rebuilds a subtree to reflect a change.
Permanent controls as the registry
Open Ptree’s home view and inspect the document. Every scientific tree in the header is an <a> carrying data-bb. Every property in the band is a radio <input name="Property"> paired with its <label>. Every legend scale holds <data value="..."> endpoints, pressed <dt> category cells, and range inputs. No JavaScript object mirrors those lists.
URL routing parses the hash against those DOM nodes directly: the first segment matches the header’s a[data-bb] links, the second matches the property radios’ labels, and the view parameter matches input[name="View"]. Changing a property’s label in the generated shell moves its URL token and its parser together.
Filtering reads the legend DOM the same way. Pressed <dt> cells supply the active category bins, range inputs supply the numeric window shares, and <data> elements supply the scale bounds. Editing one number in the markup moves both the printed bound and the filter math.
Compare builds its rows by cloning the labels already in the property menu. Even the question box’s server reads the served HTML shell through linkedom at startup to assemble its system prompt and tool enums from the same radios, legend cells, and checkboxes the visitor sees.
One attribute, several readers
One conceptual state lives in one native attribute, read by accessibility, CSS, and script alike:
aria-busy="true"is what screen readers announce, what CSS pulses, what the tour player waits on before clicking a target, and what scripts check to avoid overlapping work.aria-current="page"on a tree link names the active backbone for assistive tech, highlights the header tab in CSS, and is whatcurBackbone()reads when building the next API request.:checkedand:indeterminateon native checkboxes hold common-name display, fossil inclusion, tree sync, filtering, and branch disclosures in Tree and Cladogram.
export const curBackbone = () =>
document.querySelector("a[data-bb][aria-current]").dataset.bb;
Mutating tiles in place
A tree of life has millions of nodes, so Ptree creates and removes tiles as branches open and close. Reconciling by stable taxon ID keeps the shared prefix untouched and mutates existing nodes in place for every attribute, label, filter, and color change.
Swapping scientific and common names runs no relabel loop in JavaScript. Every tile holds both a .vern span and a .sci span in one grid cell; checking Common toggles a single Common class on <body>, and CSS swaps which span displays.
Color overlays work through registered @property custom properties (<percentage>, <color>, <number>). Switching from Mass to Longevity, or hovering from one taxon to another, calls setProperty once per changed variable. The browser interpolates the quartiles, whiskers, geometric-mean diamond, and stacked bars on its own, with no animation loop. Deleting an earlier dynamic-legend subsystem made the legend simpler and more capable because the cascade and property interpolation took over the work.
Trusting internal invariants
Because Ptree authors and mutates its own DOM, internal queries carry no optional chaining, fallback defaults, or defensive try/catch blocks. External boundaries (URLs, user clicks, upstream source files, and HTTP requests) are validated strictly; broken internal invariants crash loudly. The entire viewer runs in ~16,000 lines of framework-free ES modules with no build step in development and no virtual DOM at runtime.