I think I might be missing a key function in the purescript-dom module to convert from a Node to a specific element type. For instance if I have a Event, I can use DOM.Events.Events.target to get the Node, but it seems like the only way to get a specific element is with unsafeCoerce, e.g.
import DOM.Event.Event (target)
import DOM.HTML.HTMLInputElement (value)
eval (InputChange event next) = do
-- Get the value of the HTMLInputElement assuming it is one
v <- H.liftEff $ value (unsafeCoerce $ target event)
H.liftEff $ log "Input field change"
H.liftEff $ log v
pure next
Is there a better way to go from a Node to an element type?
The idea is to use
toForeignand thenreadHTMLInputElementwhen you want to upcast aNode/ element type.It's pretty annoying to constantly write things like that though, so
purescript-dom-classyaims to take some of the pain out of it. As well as avoiding thetoForeignstep you'll only have aMaybeto deal with, rather than theExceptareadfunction will return.