You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm having trouble using Javascript.Cast for more complex types like React's SyntheticEvent
AFAIK there is no prototype exported by React for SyntheticEvent, so my logic for detecting if a javascript value is a SyntheticEvent is e && e.nativeEvent && e.nativeEvent instanceof Event
Unfortunately, this means I cannot use Javascript.Cast since the logic for detecting instance is hard-coded to use js_checkcast, which is:
Would it be possible to invert the hard-coding and make the Cast class as follows?
class InstanceRef a where
instanceRef :: a -> JSVal
class Cast a where
unsafeWrap :: JSVal -> a
isInstance :: JSVal -> Maybe a
default isInstance :: InstanceRef a => JSVal -> Maybe a
isInstance x = js_checkCast x (instanceRef (undefined :: a))
cast :: forall a. Cast a => JSVal -> Maybe a
cast x | isInstance x = Just (unsafeWrap x)
| otherwise = Nothing
{-# INLINE cast #-}
The text was updated successfully, but these errors were encountered:
Hi, I'm having trouble using Javascript.Cast for more complex types like React's SyntheticEvent
AFAIK there is no prototype exported by React for SyntheticEvent, so my logic for detecting if a javascript value is a SyntheticEvent is
e && e.nativeEvent && e.nativeEvent instanceof Event
Unfortunately, this means I cannot use Javascript.Cast since the logic for detecting instance is hard-coded to use js_checkcast, which is:
Would it be possible to invert the hard-coding and make the Cast class as follows?
The text was updated successfully, but these errors were encountered: