I implemented a simple router, along with some helper functions, here. In the working example, we have the helper class:
implicit class RxNode(val rxNode: Rx[Node]) extends AnyVal {
def toNode(errNode: Node = <div>Error/404</div>): Node = {
val nodeOuter = <div>{ rxNode }</div>
nodeOuter.child.headOption match {
case Some(nd) => <div class="debug">{ nd }</div>
case None => errNode
}
}
}
I don't understand why the first case can't just be case Some(nd) => nd, but if you leave it as that, you will see bad things happen when you switch between the path #/counter and any other path starting with #/ (i.e., some html wills stay there and not be replaced, while new html continues to be added to the view).
I implemented a simple router, along with some helper functions, here. In the working example, we have the helper class:
I don't understand why the first
case
can't just becase Some(nd) => nd
, but if you leave it as that, you will see bad things happen when you switch between the path#/counter
and any other path starting with#/
(i.e., some html wills stay there and not be replaced, while new html continues to be added to the view).