Guest User

Untitled

a guest
Nov 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. sealed trait WhistState {
  2. def text: String
  3. def hash: String
  4.  
  5. def render: Binding[Node]
  6. }
  7.  
  8. object Router {
  9.  
  10. val defaultState: WhistState = DefaultState("Games")
  11.  
  12. val allStates: Vector[WhistState] = Vector(defaultState)
  13.  
  14.  
  15. val route: Route.Hash[WhistState] = Route.Hash[WhistState](defaultState)(new Route.Format[WhistState] {
  16.  
  17. override def unapply(hashText: String): Option[WhistState] = allStates.find(_.hash == window.location.hash)
  18. override def apply(state: WhistState): String = state.hash
  19.  
  20. })
  21.  
  22. route.watch()
  23.  
  24. }
  25.  
  26. object Application {
  27. import example.route.Router._
  28.  
  29. @dom
  30. def render: Binding[Node] = {
  31. for (hash <- route.state.bind.hash) yield println("hash: " + hash)
  32.  
  33. route.state.bind match {
  34. case default: WhistState => println("default"); default.render.bind
  35. case _ => println("none"); <div>NotFound</div>
  36. }
  37. }
  38.  
  39. def main(args: Array[String]): Unit = {
  40. dom.render(document.querySelector("#content"), render)
  41. }
  42.  
  43. }
Add Comment
Please, Sign In to add comment