Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
- }
Add Comment
Please, Sign In to add comment