Mixins / foldkit-mixins

What the resolver guarantees

Attachments are not concatenated and left to renderer order. The resolver applies explicit rules:

  • classes are additive and deduplicated into one Class;
  • inline styles from Style pieces merge per property, later attachments winning, over the view's base; a property a Behavior sets (through h.Style in its attributes) has exactly one owner, so a Style piece, the base, or a second Behavior setting the same property is an error;
  • an event or scalar attribute has exactly one owner — a second owner is an error. Owners are compared by what Foldkit really sets on the element: h.OnKeyDownPreventDefault owns keydown as h.OnKeyDown does, h.OnDoubleClick owns dblclick, and h.AriaLabel, h.Attribute('aria-label', …) and a Prop named ariaLabel share one owner;
  • a ChildAttribute (a Submodel's published handler) is preserved by identity; one a Mixin adds meets the same ownership and protection checks as its own attributes, and a child Class joins the one Class;
  • the resolver writes the one class and style, so a Mixin may not set either through h.Attribute, a Prop or a child Style, nor an inline handler (h.Attribute('onclick', …));
  • a style property is the declaration it writes, so insetInlineEnd and 'inset-inline-end' are one property. A protected property, or one a Behavior owns, is also guarded against what writes over it: a shorthand (inset, margin), its physical side (right or left for insetInlineEnd), and translate, rotate or scale beside transform;
  • Key, InnerHTML and a Prop that replaces the children are structural and cannot be overridden;
  • multiple mount contributions compose into exactly one OnMount, a Mount inside a ChildAttribute (a Submodel's) included; that one still sends through its own boundary.

Conflicts throw Diagnostics.DiagnosticError with stable codes such as mixins:event-conflict, mixins:style-property-conflict and mixins:protected-attribute, so tests, DevTools and editor tooling can all speak the same diagnostic language. A conflict between two owners (an event, an attribute, a style property, a Mount name) names both contributors in its message and in details.contributors: each attachment by its name, and the view for the base attributes the render passed. The style rule exists because a positioning Behavior that writes top and a Style that also sets top would otherwise fight silently, last writer winning. A theme refuses its values the same way: Theme.make with a value out of a knob's range throws theme:knob-value, naming the call and the knob (Theme.make: surface.lightness refuses its value: …), and an unknown knob theme:unknown-knob.

Those are definition errors, thrown. One thing goes wrong only at runtime: a Mount composed beside others that fails. It ends alone, so the slot's other Mounts go on, and it is reported as a MountFailed diagnostic ({ mount, slot, cause }, level error) through foldkit-surface's Diagnostics channel, which by default is Effect's log (the console). A Mount that ends interrupted is being torn down with its element and reports nothing. Foldkit runs a Mount in the runtime's own context, not its resources, so the resolver dispatches the diagnostic at the Mount's element (Diagnostics.dispatch), and a reporter given with Diagnostics.layer(reporter) in the resources claims it; without one it goes to the log. A test runs the Mount's stream with Effect.provideService(Diagnostics.Reporter, collected.report), where collected is Diagnostics.collect() (both from foldkit-surface), and asserts on collected.reported.

In development, DevOverlay lists on the page what the application's reporter heard, Mount failures included:

ts
import { Diagnostics } from 'foldkit-surface'
import { DevOverlay } from 'foldkit-mixins'

const overlay = DevOverlay.make() // the newest 50; each passed on to Diagnostics.log
const resources = Diagnostics.layer(overlay.report)
// In the view, behind the application's development flag:
// h.div([h.OnMount(overlay.mount)], [])

The panel is drawn in its element's shadow root, fixed in the bottom corner, with a Clear button, and nothing while the list is empty. It sends no Message, so draw it only in development: a Scene test of a page that draws it cannot resolve it. The resolver's thrown Diagnostics namespace here is a different thing: import one of the two under another name.