scalatags-rx
scalatags-rx copied to clipboard
stealing nodes
Priwiet :)
I discovered supprising feature.
Bindings:
bindRxElement[T <: dom.Element](e: Rx[T]) ...
and
bindRxElements(e: Rx[immutable.Iterable[Element]]) ...
expect dom.Element
s. This means that it's easy to lost nodes in html because such node can be appended to only one parent. Every time when appended to new parent, the relation with old parent is lost. Of course developer can watch every time when playing with nodes, nevertheless it would be beneficial if library won't support such desings.
Here is simple demo of sealing nodes:
val abcDiv = Var(div("abc").render)
val p1 = p(abcDiv).render
println("p1: ", p1.outerHTML)
assert(p1.outerHTML == "<p><div>abc</div></p>")
val s1 = span(abcDiv).render //this will steal abcDiv node and bind it into new place
println("p1: ", p1.outerHTML) // <p/>
println("s1: ", s1.outerHTML) // <span><div>abc</div></span>
assert(p1.outerHTML == "<p><div>abc</div></p>") //Boom p1.outerHtml is <p/>
More iteresting things happen when abcDiv changes, or when abcDiv
is declared as Rx[Iterable[dom.Element]]
.
As solution to this I propose to rewrite:
implicit class bindRxElement[T <: dom.Element](e: Rx[T]) ...
implicit class bindRxElements(e: Rx[immutable.Iterable[Element]])...
accordingly to
implicit class bindRxFrag[T <: Frag](e: Rx[T]) ...
implicit class bindRxFrag[T <: Frag](e: Rx[T]) ...
How do you think?