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
-
MatchedRoute( path: String, pattern: String, view_id: String, params: List(RouteParam), decode_event: fn(event.InboundEvent, List(RouteParam)) -> Result( msg, event.DecodeError, ), )
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
-
Route( pattern: String, view_id: String, decode_event: fn(event.InboundEvent, List(RouteParam)) -> Result( msg, event.DecodeError, ), )
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)
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 resolve(
router: Router(msg),
path: String,
) -> RouteMatch(msg)
Resolve one path into a route match.