Primitives / foldkit-primitives/media

MediaQuery

const · packages/primitives/src/media/mediaquery.ts:57

Args{ query: string, initial?: boolean }
Model{ matches: boolean }
MessagesChanged { matches: boolean }
Its full type
const MediaQuery: Bundle.Bundle<
  'MediaQuery',
  { readonly query: string; readonly initial?: boolean },
  { readonly matches: boolean },
  { readonly _tag: 'Changed'; readonly matches: boolean },
  never,
  never,
  never,
  NoView,
  {},
  {},
  undefined
>

A media query as a bundle: matches in the Model, kept current by a matchMedia change stream. State stays in the parent Model, so it replays and time-travels like any other state; the browser only reports facts.

matches starts as the window answers at init, so the first frame is drawn for the screen it is on: the stream's own first report comes with the Subscriptions, after that frame. args.initial says it instead, for a server that knows the device from a request hint, or a test.

In the guides