Primitives / Events
Start with one: is the tab visible
ts
import { Schema } from 'effect'
import type { HtmlBuilder } from 'foldkit/html'
import { Bundle } from 'foldkit-bundle'
import { Visibility } from 'foldkit-primitives/events'
const Page = Bundle.compose({}).pipe(Bundle.withChild('tab', Visibility))
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([], [model.tab.visible ? 'Watching' : 'Paused']),
subscriptions: placements.subscriptions(),
})init reads the document when there is one and assumes visible on a server;
visibilitychange keeps it current. A hidden page is the application's cue to
pause polling and streams; that decision stays in your update, not here.