Primitives / Device
Start with one: where the device is
ts
import { Schema } from 'effect'
import type { HtmlBuilder } from 'foldkit/html'
import { Bundle } from 'foldkit-bundle'
import { Geolocation } from 'foldkit-primitives/device'
const Page = Bundle.compose({}).pipe(Bundle.withChild('here', Geolocation))
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.here.status]),
subscriptions: placements.subscriptions(),
})The status starts unknown with no coordinates. Subscribing starts
watchPosition; Located stores a fix and marks it ready. Denied is its
own status (permission code 1), which a view can act on; any other error is
Failed, which keeps the last fix and notes lastError. coords and every
bundle's lastError here are Options, stored as null in JSON. Unsubscribing clears
the watch. Without a geolocation API the stream is empty.