OlivierBlanvillain / monadic-html

Tiny DOM binding library for Scala.js
https://olivierblanvillain.github.io/monadic-html/examples/
MIT License
225 stars 24 forks source link

<div> wrapping needed when switching views #77

Open bbarker opened 6 years ago

bbarker commented 6 years ago

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).