ContextRouteBuilder

class ContextRouteBuilder[Bundle, Page, Ctx, CtxArgs](encodeContext: Ctx => CtxArgs, decodeContext: CtxArgs => Ctx, contextPattern: QueryParameters[CtxArgs, DummyError], pageFromBundle: Bundle => Page, contextFromBundle: Bundle => Ctx, bundleFromPageWithContext: (Page, Ctx) => Bundle)(`evidence$1`: ClassTag[Bundle], `evidence$2`: ClassTag[Ctx])

A builder for routes with context.

A builder for routes with context.

Context, in this context (heheh), is a type that encodes a set of query params that is shared between the routes created by this builder.

For example, your Laminar web app might have a big documentation section with many routes, but where every route is expected to have a "lang" query param to indicate the selected language and a "version" param to indicate the product version (unrealistic doc standards, I know).

So, you could add these two params to every page type that needs them and to every route for those page types, but that could be annoying. So instead, you could create a ContextRouteBuilder which will let you specify the necessary types / conversions / patterns only once.

See ContextRouteBuilderSpec for a concrete example.

Type Params
Bundle
  • The type of pages (including the context part) handled by the routes produced by this builder. A bundle consists of a route-specific Page, and a Context shared by all routes by this builder. In the simplest case, imagine case class Bundle(p: Page, ctx: Context)
Ctx
  • The part of the Bundle shared by all routes made by this builder, In the simplest case, imagine case class SharedParams(lang: Option[String], version: Option[String])
Page
  • The base type for the route-specific parts of the Bundle
class Object
trait Matchable
class Any

Value members

Concrete methods

def apply[P <: Page, PageArgs](encode: P => PageArgs, decode: PageArgs => P, pattern: PathSegment[PageArgs, DummyError])(`evidence$3`: ClassTag[P]): Route[Bundle, UrlMatching[PageArgs, CtxArgs]]

Create a context route for pages that are encoded in path segments only

Create a context route for pages that are encoded in path segments only

def onlyQuery[P <: Page, PageArgs](encode: P => PageArgs, decode: PageArgs => P, pattern: PathSegmentWithQueryParams[Unit, DummyError, PageArgs, DummyError])(`evidence$4`: ClassTag[P]): Route[Bundle, (PageArgs, CtxArgs)]

Create a context route for pages that are encoded in query params only

Create a context route for pages that are encoded in query params only

def static(staticPage: Page, pattern: PathSegment[Unit, DummyError]): Route[Bundle, UrlMatching[Unit, CtxArgs]]

Create a context route for an otherwise static page.

Create a context route for an otherwise static page.

That is, while the Page itself does not encode any data in the URL, the bundle does encode context args in the query.

def withQuery[P <: Page, PathArgs, QueryArgs](encode: P => UrlMatching[PathArgs, QueryArgs], decode: UrlMatching[PathArgs, QueryArgs] => P, pattern: PathSegmentWithQueryParams[PathArgs, DummyError, QueryArgs, DummyError])(`evidence$5`: ClassTag[P]): Route[Bundle, UrlMatching[PathArgs, (QueryArgs, CtxArgs)]]

Create a context route for page that are encoded in both path segments in query params

Create a context route for page that are encoded in both path segments in query params