Primitives / Motion
Start with one: a tween
import { Schema } from 'effect'
import type { HtmlBuilder } from 'foldkit/html'
import { Bundle } from 'foldkit-bundle'
import { Tween, TweenMessage } from 'foldkit-primitives/motion'
const Page = Bundle.compose({}).pipe(
Bundle.withChild('slide', Tween, { args: { from: 0, to: 1, ms: 200 } }),
)
type Model = typeof Page.Model.Type
type Message = typeof Page.Message.Type
const { placements } = Page
const config = placements.complete({
init: () => placements.initial({}),
update: placements.update(model => ({ model })),
view: (model: Model, h: HtmlBuilder<Message>) =>
h.div(
[
h.Style({ opacity: String(model.slide.value) }),
h.OnClick(Page.Message.GotSlideMessage({ message: TweenMessage.Started() })),
],
['Fade in'],
),
subscriptions: placements.subscriptions(),
})The tween starts at from, stopped. Started runs it; progress comes from
Effect's clock, so a test advances it with TestClock. The stream ends with
Finished carrying the exact end value, and the value rests at to either
way. Stopped holds the current value; a new Started runs from to to
again. Linear interpolation only. A duration that is not positive and finite is
rejected at placement.
Spring
Pulls one number toward to with { stiffness, damping } physics (positive
and finite). A fixed 16 ms semi-implicit Euler step makes the trajectory
identical on the live clock and TestClock; the stream ends with Finished
carrying the exact end value even when an underdamped spring overshoots on the
way. Tween is a fixed duration; Spring settles. Pick the motion, not both.