Browse Source

Fix blank url pushstate (#7)

* Update dependencies

* Fix Root path string

Add a method toUrlString that provides a default path as "/" for Root
master
Zak Patterson 5 years ago
committed by GitHub
parent
commit
211941d1cb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      build.sbt
  2. 11
      outwatch-router/src/main/scala/outwatch/router/Path.scala
  3. 15
      outwatch-router/src/test/scala/outwatch/router/AppRouterTestSpec.scala
  4. 2
      project/build.properties
  5. 4
      project/plugins.sbt

12
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")

11
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
}

15
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")
}

2
project/build.properties

@ -1 +1 @@
sbt.version=1.2.3
sbt.version=1.3.0-RC2

4
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")

Loading…
Cancel
Save