Yeah, the web-events library only provides for things that are mentioned in the spec specifically.
Personally, I’d probably implement accessors for custom things from events in an FFI module in my app. Alternatively you could coerce to Foreign, and use the functions for that to read from it.
@garyb do you mean accessor functions in the JS side of the app? I could do that … just that constructing the purescript value in JS is not so easy. So i could end up with 7 accessor functions in JS and one construction function on the purescript side.
Thanks for your advice, i will look at coercering to Foreign first to keep it all contained in a single function. Why is this not your preference ?
type AddItemEvent =
{ id :: Int
, value :: String
, label :: String
, customProperties :: Foreign
, groupValue :: String
, keyCode :: Int
}
unsafeConvertEvent :: forall a b c. (Foreign -> ExceptT c Identity b) -> a -> b
unsafeConvertEvent f e = unsafePartial $ fromRight $ runExcept $ f $ unsafeToForeign e
onAddItem :: forall r i. (AddItemEvent -> Maybe i) -> HP.IProp r i
onAddItem f = HE.handler (EventType "addItem") (\e -> f (unsafeConvertEvent convert e))
where convert e = do
id <- e ! "id" >>= readInt
value <- e ! "value" >>= readString
label <- e ! "label" >>= readString
customProperties <- e ! "customProperties"
groupValue <- e ! "groupValue" >>= readString
keyCode <- e ! "keyCode" >>= readInt
pure { id, value, label, customProperties, groupValue, keyCode }