Primitives / foldkit-primitives
Rules every primitive keeps
These guarantees hold across every subpath:
- Unchanged facts preserve Model identity. When a resize, start, or update produces the same value, the placement returns the parent Model unchanged so Foldkit skips re-rendering and
createLazyviews stay cached. - Initial values are safe defaults, not live reads. Slices start at safe values (
matches: false,online: true,0) for server rendering; the subscription updates them once mounted in a browser. - Missing platform APIs degrade gracefully. Streams stay empty, Commands yield failure Messages (
CopyFailed,ShareFailed), and Mounts stay idle rather than throwing. - One placement observes once. Share a single placed field across components that read the same query;
assemblerefuses duplicate module-scoped resource tags such as sockets or camera streams. - Settled values require
onOut. Primitives that emit outcomes (debounce,Throttle,Press,DismissLayer) requireonOutwhen placed, orBundle.ignoreto opt out explicitly. - Timed work runs on Effect's clock. Timers, tweens, debounces, and idle detectors advance deterministically under
TestClock.adjust. - Reduced motion uses the
Motionservice. ProvideMotion.livein your runtime resources, orMotion.reduced/Motion.fullin tests; full motion is the default when omitted. - DOM elements stay out of the Model. Focus and mutation reports carry serializable ids and metadata (
{ tag, id }) rather than element references.
Testing a placement
Three patterns cover primitive tests without global mocks:
- Substitute the environment. Factories accept
create(streams, devices, permissions, sockets) orrequest(camera) doubles so tests pass deterministic fakes. - Advance time with
TestClock.adjust. Yield once after forking a subscription so listeners register before advancing the clock. - Bound stream reads. Collect test outputs with a bounded
Stream.takeso a stalled stream fails quickly with a clear message.
Composing with Surface and Mirror
Placed primitive state lives in your ordinary Model, so you can read it in a foldkit-surface projection, expose it to an agent, or persist it in the URL with Mirror.url. For state that must survive page reloads via KeyValueStore, pair it with Mirror.kv; primitives track live session facts only.
Limits
- Built-in presets cover common media queries; custom queries pass
args. Virtualwindows a single scroll axis; 2D virtualized grids are outside its scope.- Collaborative merging and offline outboxes belong in
foldkit-sync.
Next
- Place and wire multiple primitives cleanly:
foldkit-bundle. - Build styled components from interaction primitives: Authoring components.
- Use ready-made styled widgets built on these primitives:
foldkit-mixins-ui.