lightspeed/router

Router integration helpers for mount/render flows.

Types

Resolved route and captures.

pub type MatchedRoute(msg) {
  MatchedRoute(
    path: String,
    pattern: String,
    view_id: String,
    params: List(RouteParam),
    decode_event: fn(event.InboundEvent, List(RouteParam)) -> Result(
      msg,
      event.DecodeError,
    ),
  )
}

Constructors

Route definition with view identity and typed event decoder.

pub type Route(msg) {
  Route(
    pattern: String,
    view_id: String,
    decode_event: fn(event.InboundEvent, List(RouteParam)) -> Result(
      msg,
      event.DecodeError,
    ),
  )
}

Constructors

Result of resolving a path through the router.

pub type RouteMatch(msg) {
  Found(MatchedRoute(msg))
  NotFound(path: String, view_id: String)
}

Constructors

  • Found(MatchedRoute(msg))
  • NotFound(path: String, view_id: String)

One named parameter captured from a route pattern.

pub type RouteParam {
  RouteParam(name: String, value: String)
}

Constructors

  • RouteParam(name: String, value: String)

Router table.

pub type Router(msg) {
  Router(not_found_view: String, routes_rev: List(Route(msg)))
}

Constructors

  • Router(not_found_view: String, routes_rev: List(Route(msg)))

Values

pub fn add(
  router: Router(msg),
  pattern: String,
  view_id: String,
  decode_event: fn(event.InboundEvent, List(RouteParam)) -> Result(
    msg,
    event.DecodeError,
  ),
) -> Router(msg)

Register a route pattern.

pub fn decode(
  matched: MatchedRoute(msg),
  inbound: event.InboundEvent,
) -> Result(msg, event.DecodeError)

Decode one inbound event against a matched route decoder.

pub fn match_label(route_match: RouteMatch(msg)) -> String

Render stable route match labels for logs.

pub fn mount_instructions(
  route_match: RouteMatch(msg),
  csrf_token: String,
) -> List(isa.Instruction)

Build a mount/render ISA sequence for a resolved route.

pub fn new(not_found_view: String) -> Router(msg)

Create a new router with a fallback not-found view.

pub fn params(matched: MatchedRoute(msg)) -> List(RouteParam)

Matched route captured params.

pub fn resolve(
  router: Router(msg),
  path: String,
) -> RouteMatch(msg)

Resolve one path into a route match.

pub fn view_id(matched: MatchedRoute(msg)) -> String

Matched route view id.

Search Document