Skip to content

Commit

Permalink
Naming: Route.static -> staticPartial; staticTotal -> static
Browse files Browse the repository at this point in the history
Originally we could not use staticTotal as the default static because we could not enforce the argument being a singleton, however we discovered ValueOf, which makes it safe, thus ok to use by default.
  • Loading branch information
raquo committed Dec 10, 2024
1 parent af71f34 commit d302ab6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ _You can now [sponsor](https://github.com/sponsors/raquo) Laminar / Airstream /
* **Build: Waypoint depends on Laminar now (not just Airstream)**
* New: `navigateTo` example method from the docs is now available on `Router`
* Unlike the example, it does not reset scroll position – do that yourself by observing to `currentPageSignal`
* _Migration: `Router` constructor is now a single argument list, `popStateEvents` and `owner` now have default values._
* _**Migration:** `Router` constructor is now a single argument list, `popStateEvents` and `owner` now have default values._
* **New: Total and Partial route types, to improve type-safety for the total routes.**
* New: `route.argsFromPageTotal` and `route.relativeUrlForPage` available on `Route.Total` subtype of `Route`.
* _**Migration:** If `Route.static` complains that it can't find `ValueOf` for your page type, it's because your type is not a singleton like `object LoginPage`, so we can't make a total route for it. Use `Route.staticPartial` instead._
* New: `Router.replacePageTitle`
* Fix: `SplitRender.signal` should be a lazy val, not def.
* Build: scalamft config

#### v8.0.1 – Aug 2024
* Build: Update URL DSL to 0.6.2
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import VersionHelper.{versionFmt, fallbackVersion}
// Get Maven releases faster
resolvers ++= Resolver.sonatypeOssRepos("public")

lazy val preload = taskKey[Unit]("runs Laminar-specific pre-load tasks")
lazy val preload = taskKey[Unit]("runs Waypoint-specific pre-load tasks")

preload := {
val projectDir = (ThisBuild / baseDirectory).value
Expand Down
4 changes: 2 additions & 2 deletions js/src/test/scala/com/raquo/waypoint/BasePathSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class BasePathSpec extends UnitSpec {
// they are overlapping – that is not a real life condition.
// - Add a bool parameter to `runTest` that would add one or the other to routes?

val homeRoute: Route[HomePage.type, Unit] = Route.static(
val homeRoute: Route[HomePage.type, Unit] = Route.staticPartial(
HomePage,
pattern = root / endOfSegments,
basePath = basePath
)

val homeRouteTotal: Route.Total[HomePage.type, Unit] = Route.staticTotal(
val homeRouteTotal: Route.Total[HomePage.type, Unit] = Route.static(
HomePage,
pattern = root / endOfSegments,
basePath = basePath
Expand Down
37 changes: 18 additions & 19 deletions shared/src/main/scala/com/raquo/waypoint/Route.scala
Original file line number Diff line number Diff line change
Expand Up @@ -439,19 +439,19 @@ object Route {

/** Create a route for a static page that does not encode any data in the URL.
*
* This returns a [[Partial]] route. If you want a [[Total]] route,
* use [[staticTotal]] instead. They behave the same, but the total version
* offers a couple extra methods, but it requires that the `staticPage` is
* a singleton (e.g. `object HomePage`).
* This version only allows using singleton types, like `object Foo`.
* See [[staticPartial]] for a more relaxed version.
*
* @see [[ValueOf]] - evidence that `Page` is a singleton type
*/
def static[Page](
def static[Page: ValueOf: ClassTag](
staticPage: Page,
pattern: PathSegment[Unit, DummyError],
basePath: String = ""
): Partial[Page, Unit] = {
new Partial[Page, Unit](
matchEncodePF = { case p if p == staticPage => () },
decodePF = { case _ => staticPage },
): Total[Page, Unit] = {
new Total[Page, Unit](
encode = _ => (),
decode = _ => staticPage,
createRelativeUrl = args => "/" + pattern.createPath(args),
matchRelativeUrl = relativeUrl => pattern.matchRawUrl(relativeUrl).toOption,
basePath = basePath
Expand All @@ -460,23 +460,22 @@ object Route {

/** Create a route for a static page that does not encode any data in the URL.
*
* This version only allows using singleton types, like `object Foo`.
* See [[static]] for a more relaxed version.
*
* @see [[ValueOf]] - evidence that `Page` is a singleton type
* This returns a [[Partial]] route. If you want a [[Total]] route,
* use [[static]] instead. They behave the same, but the total version
* offers a couple extra methods, but it requires that the `staticPage` is
* a singleton (e.g. `object HomePage`).
*/
def staticTotal[Page: ValueOf: ClassTag](
def staticPartial[Page](
staticPage: Page,
pattern: PathSegment[Unit, DummyError],
basePath: String = ""
): Total[Page, Unit] = {
new Total[Page, Unit](
encode = _ => (),
decode = _ => staticPage,
): Partial[Page, Unit] = {
new Partial[Page, Unit](
matchEncodePF = { case p if p == staticPage => () },
decodePF = { case _ => staticPage },
createRelativeUrl = args => "/" + pattern.createPath(args),
matchRelativeUrl = relativeUrl => pattern.matchRawUrl(relativeUrl).toOption,
basePath = basePath
)
}

}

0 comments on commit d302ab6

Please sign in to comment.