Mixins / foldkit-mixins-surface
Attach typed Behaviors without repeating types
Behavior.forSlots requires the exact projected input type because SlotView is invariant in its input. Use SurfaceView.over(surface, slots) to bind both the projection type and Message subset once so Styles and Behaviors need no manual type parameters:
import { Behavior } from 'foldkit-mixins'
const Todos = SurfaceView.over(TodoList, TodoSlots)
const Archives = Todos.behavior({
archive: {
requires: { events: [Event.Click] },
attributes: ({ input, h }) =>
Option.match(input.selected, {
onNone: () => [],
onSome: id => [h.OnClick(Message.Archived({ id }))],
}),
},
})
const BoundTodoListView = Todos.define((_model, slots, h) =>
h.section(slots.root.attrs(), [h.button(slots.archive.attrs(), ['Archive selected'])]),
).pipe(Behavior.attach(Archives))Inside Todos.behavior, input.secret is a type error and h restricts Messages to Selected and Archived. Apply slots.archive.attrs(...) to the element where Behavior attributes should attach.
Render statically for tests and demos
SurfaceView.render(view, surface, params, root) projects root through the Surface and renders static Html using SlotView.inertBuilder without mounting a runtime or dispatching events:
const html = SurfaceView.render(TodoListView, TodoList, undefined, {
todos: ['Write docs'],
selected: Option.some('t1'),
secret: 'not projected',
})Inspect a SurfaceView
SurfaceView.describe(surface, params, view) merges SlotView.describe(view) (slots, attachments, requirements, contributions, and findings) with Surface.inspect (observed fields, projection metadata, and emitted Message tags). SurfaceView.toMarkdown formats that inspection output as Markdown for snapshots or documentation checks. Each helper (define, over, toRenderer, render, describe, toMarkdown) is also available as a direct named export.
Next
- Learn Slots, Styles, and Behaviors:
foldkit-mixins - Define Surfaces and Modules:
foldkit-surface - See a full Surface-to-SlotView example:
examples/mixins