From 211941d1cb29936faa113f53b711b10498540144 Mon Sep 17 00:00:00 2001 From: Zak Patterson Date: Sun, 14 Jul 2019 17:03:44 -0500 Subject: [PATCH] Fix blank url pushstate (#7) * Update dependencies * Fix Root path string Add a method toUrlString that provides a default path as "/" for Root --- build.sbt | 12 ++---------- .../src/main/scala/outwatch/router/Path.scala | 11 +++++++++-- .../scala/outwatch/router/AppRouterTestSpec.scala | 15 +++++++++++++++ project/build.properties | 2 +- project/plugins.sbt | 4 ++-- 5 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 outwatch-router/src/test/scala/outwatch/router/AppRouterTestSpec.scala diff --git a/build.sbt b/build.sbt index bc9fa35..06d4e5b 100644 --- a/build.sbt +++ b/build.sbt @@ -8,7 +8,7 @@ val compilerPlugins = Seq( ) val versions = new { - val scalatest = "3.0.5" + val scalatest = "3.1.0-SNAP11" val outwatch = "676f94a" } @@ -73,11 +73,8 @@ lazy val router = project .enablePlugins(ScalaJSBundlerPlugin) .settings(commonSettings) .settings( - scalaJSModuleKind := ModuleKind.CommonJSModule, - scalacOptions += "-P:scalajs:sjsDefinedByDefault", useYarn := true, // makes scalajs-bundler use yarn instead of npm - jsEnv in Test := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv, - scalaJSModuleKind := ModuleKind.CommonJSModule, // configure Scala.js to emit a JavaScript module instead of a top-level script + requireJsDomEnv in Test := true, version in webpack := "4.16.1", version in startWebpackDevServer := "3.1.4", webpackDevServerExtraArgs := Seq("--progress", "--color"), @@ -102,11 +99,6 @@ lazy val router = project ) .settings(publishSettings) -lazy val exampleApp = (project in file("router-example")) - .settings(name := "outwatch-example") - .settings(commonSettings) - .dependsOn(router) - lazy val root = project .in(file(".")) .settings(name := "outwatch-router-root") diff --git a/outwatch-router/src/main/scala/outwatch/router/Path.scala b/outwatch-router/src/main/scala/outwatch/router/Path.scala index e19af3d..8ca1e91 100644 --- a/outwatch-router/src/main/scala/outwatch/router/Path.scala +++ b/outwatch-router/src/main/scala/outwatch/router/Path.scala @@ -15,6 +15,8 @@ trait Path { def parent: Path def lastOption: Option[String] def startsWith(other: Path): Boolean + def pathString: String + def toUrlString: String = if (pathString.isEmpty) "/" else pathString } object Path { @@ -80,8 +82,12 @@ final case class /(parent: Path, child: String) extends Path { def lastOption: Some[String] = Some(child) - lazy val asString: String = s"$parent/${UrlCodingUtils.pathEncode(child)}" + lazy val asString: String = s"${parent.pathString}/${UrlCodingUtils.pathEncode(child)}" + override def toString: String = asString + + def pathString: String = asString + def startsWith(other: Path): Boolean = { val components = other.toList toList.take(components.length) === components @@ -115,7 +121,8 @@ case object Root extends Path { def toList: List[String] = Nil def parent: Path = this def lastOption: None.type = None - override def toString = "" + override def toString = "Root" + def pathString: String = "" def startsWith(other: Path): Boolean = other == Root } diff --git a/outwatch-router/src/test/scala/outwatch/router/AppRouterTestSpec.scala b/outwatch-router/src/test/scala/outwatch/router/AppRouterTestSpec.scala new file mode 100644 index 0000000..e0092e2 --- /dev/null +++ b/outwatch-router/src/test/scala/outwatch/router/AppRouterTestSpec.scala @@ -0,0 +1,15 @@ +package outwatch +package router + +import org.scalatest._ +import org.scalatest.flatspec.AnyFlatSpec + +class PathTestSpec extends AnyFlatSpec with Matchers { + class PathTest(url: String, path: Path){ + path.toUrlString should equal (url) + } + + "Root url" should "be /" in new PathTest("/", Root) + "A 1 part path" should "be correct" in new PathTest("/search", Root / "search") +} + diff --git a/project/build.properties b/project/build.properties index 0cd8b07..c9f2946 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.2.3 +sbt.version=1.3.0-RC2 diff --git a/project/plugins.sbt b/project/plugins.sbt index 94f7d4a..2961453 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,5 @@ -addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.13.1") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.26") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28") +addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.15.0-0.6") addSbtPlugin("org.scalameta" % "sbt-mdoc" % "1.2.8" ) addSbtPlugin("com.47deg" % "sbt-microsites" % "0.8.0") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")