我正在尝试为Binding.scala的一个个人项目构建一个通用路由器。
我已经定义了一个PageState特征
sealed trait WhistState {
def text: String
def hash: String
def render: Binding[Node]
}每种路由类型都有多个子类。然后,我尝试创建一个路由器,它根据散列选择正确的类。
object Router {
val defaultState: WhistState = DefaultState("Games")
val allStates: Vector[WhistState] = Vector(defaultState)
val route: Route.Hash[WhistState] = Route.Hash[WhistState](defaultState)(new Route.Format[WhistState] {
override def unapply(hashText: String): Option[WhistState] = allStates.find(_.hash == window.location.hash)
override def apply(state: WhistState): String = state.hash
})
route.watch()
}然后我是我的应用程序类,我试着使用这个
object Application {
import example.route.Router._
@dom
def render: Binding[Node] = {
for (hash <- route.state.bind.hash) yield println("hash: " + hash)
route.state.bind match {
case default: WhistState => println("default"); default.render.bind
case _ => println("none"); <div>NotFound</div>
}
}
def main(args: Array[String]): Unit = {
dom.render(document.querySelector("#content"), render)
}
}我已经预料到更改散列将强制重新计算route.state.bind match ...表达式。
你知道为什么这个不起作用吗?
诚挚的问候
https://stackoverflow.com/questions/47451630
复制相似问题