Mixins / foldkit-mixins-surface
mixins-surface
When using foldkit-surface alongside foldkit-mixins, you can end up declaring the same feature boundary twice: once on the Surface (which Model fields a feature reads and which Messages it emits) and again on the SlotView (its input type and Message union). If those declarations drift, a Behavior attachment might read an omitted Model field or emit an unexposed Message.
foldkit-mixins-surface connects them with SurfaceView.define and SurfaceView.over. A Surface's projected value becomes the SlotView's input type, and its exposed Message subset becomes the SlotView's Message universe—enforced at compile time with no extra runtime state.
If you do not use foldkit-surface, use SlotView.define or SlotView.forMessages from foldkit-mixins directly. For background on Slots, Styles, and Behaviors, read Inside-out view composition.
Install
pnpm add foldkit-mixins foldkit-surface foldkit-mixins-surfacefoldkit, effect, foldkit-mixins, and foldkit-surface are peer dependencies.
A first surface-bound SlotView
Define a Surface and Slots, bind them with SurfaceView.define, and pass the result to Surface.view:
import { Option, Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Capability, Event, Slot, Slots, Style } from 'foldkit-mixins'
import { SurfaceView } from 'foldkit-mixins-surface'
import { Surface } from 'foldkit-surface'
const Model = Schema.Struct({
todos: Schema.Array(Schema.String),
selected: Schema.Option(Schema.String),
secret: Schema.String,
})
const Message = defineMessageUnion({
Selected: { id: Schema.String },
Archived: { id: Schema.String },
ClearedSecret: {},
})
const App = Surface.application({ Model, Message })
const TodoList = App.surface('TodoList', {
model: ({ model }) => ({ todos: model.todos, selected: model.selected }),
messages: [Message.Selected, Message.Archived],
})
const TodoSlots = Slots.define({
root: Slot.make({ capability: Capability.Container }),
archive: Slot.make({ capability: Capability.Interactive, events: [Event.Click] }),
})
const TodoListView = SurfaceView.define(TodoList, TodoSlots, (model, slots, h) =>
h.section(slots.root.attrs(), [
h.button(slots.archive.attrs([h.Disabled(Option.isNone(model.selected))]), ['Archive']),
]),
).pipe(Style.attach(Style.forSlots(TodoSlots)({ root: Style.class('todo-list') })))
const renderer = Surface.view(TodoList, SurfaceView.toRenderer(TodoListView))Inside SurfaceView.define, model is inferred as { readonly todos: readonly string[]; readonly selected: Option.Option<string> } (excluding secret), and h accepts only Selected and Archived Messages (rejecting ClearedSecret). SurfaceView.toRenderer adapts the SlotView for Surface.view or Surface.rootView.