pawel.panasewicz pawel.panasewicz - 1 year ago 91
Scala Question

scalatags TypedTag from HTMLElement

Is it possible to create

in scalatags?

is straightforward:

import scalatags.JsDom.all._

val typedTag: TypedTag[Div] = div("abc")
val d: Div = typedTag.render
//somwhere `type Div = raw.HTMLDivElement`

Is it possible to create conversion in opposit direction?
Given instance of
I want
in order to manipulate it using scalatags goodies and then render it back to
. Does it make sense?

Answer Source

Sadly, no -- that doesn't actually make any sense if you think it through, at least not that way. The thing is, a TypedTag isn't an HTML element, it's something that builds an HTML element. By contrast, the HTMLElement is an actual element. So basically, you're trying to get a bag of cocoa powder from an already-mixed cup.

I suspect it would be possible to build what you're asking for, but it would be a bit involved -- you'd have to build something that takes an HTMLElement and maps back to a TypedTag parameterized for that element type, then work with the TypedTag, render it and replace the existing HTMLElement in-page. It could be done, but I suspect it's more work than it's worth...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download