All files / app init.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 3/3
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                            1x     4x 1x     4x                            
import { Option } from 'effect'
import type { Runtime } from 'foldkit'
 
import { LatLon } from '../core/domain'
import { parseCoordinate } from '../core/systems/registry'
import * as Copy from '../submodels/copy'
import * as GoTo from '../submodels/goTo'
import * as Settings from '../submodels/settings'
import type { Message } from './message'
import { CursorState, type Flags, MapState, type Model } from './model'
 
// INIT
 
/** A cue in the link (`?p=`) takes any format the search box accepts. */
const cueFromQuery = (
  maybeQuery: Option.Option<string>,
): Option.Option<LatLon.LatLon> =>
  Option.map(Option.flatMap(maybeQuery, parseCoordinate), ({ point }) =>
    LatLon.clampToWorld(point),
  )
 
export const init: Runtime.ApplicationInit<Model, Message, Flags> = flags => ({
  model: {
    mapState: MapState.Loading(),
    maybeCamera: flags.maybeCamera,
    maybeCameraRequest: Option.none(),
    cursor: CursorState.Idle(),
    maybeCue: cueFromQuery(flags.maybeCueQuery),
    settings: Settings.init(flags.maybeSavedSettings),
    goTo: GoTo.init(),
    copy: Copy.init(),
    layout: flags.layout,
    pointer: flags.pointer,
  },
})