Primitives / Network
Start with one: online or not
ts
import { Schema } from 'effect'
import type { HtmlBuilder } from 'foldkit/html'
import { Bundle } from 'foldkit-bundle'
import { Online } from 'foldkit-primitives/net'
const Page = Bundle.compose({}).pipe(Bundle.withChild('net', Online))
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.net.online ? 'Online' : 'Offline']),
subscriptions: placements.subscriptions(),
})init reads navigator.onLine when there is one and assumes online
otherwise; the window's online and offline events keep it current. This is
the browser's connectivity hint, not proof that your server answers. Keep
request failures in your data-loading state.