Primitives / foldkit-primitives
Which form a primitive takes
Every primitive is one of five things, chosen by what it has to own:
| It needs to own | Form | Joins the application by | Examples |
|---|---|---|---|
| A fact that outlives the moment: a match, a count, a page, a position | bundle | placing it in the parent, as a field and a wrapper Message | MediaQuery, Timer, Pagination, websocket |
| Interaction state a view's slots must reflect | bundle + Behavior | placing it, then attaching its Behavior to the view's slots | RovingTabindex, Press, DismissLayer |
| Nothing: a stream you react to | entry | lifting it into your Subscriptions, mapped to your Message | keyboardEvents, ticks, broadcastMessages |
| Nothing: observation bound to one element | Mount | attaching it in the view with h.OnMount | Resize, Autofocus, KeepInView |
| Nothing: work done once that reports back | Command | returning it from update | copyText, share, enterFullscreen |
| Nothing: a value computed from what you have | function | calling it | range, matchHotkey, formatRelativeTime |
The lighter form wins when in doubt. Promote to a bundle the day the state needs a name in the Model.
The one dependency is foldkit-bundle, whose placement
mechanism every bundle here uses. interaction additionally needs
foldkit-mixins, an optional peer, because its Behaviors write to
a view's slots.
Install
bash
pnpm add foldkit-primitives foldkit-bundle effect foldkiteffect and foldkit are peer dependencies. Import by subpath (/media,
/net, /time, /state, /motion, /interaction, /device, /events,
/observers, /dom) so a bundler drops what you never import.