Use FromJSVal for props
This commit is contained in:
parent
191ae58b73
commit
e4b862f1b5
@ -8,13 +8,16 @@ import React.JSaddle
|
||||
import React.Types
|
||||
|
||||
--TODO: The Hook section shouldn't have any control flow to it; probably it also shouldn't depend on props except in specific ways
|
||||
component :: (JSVal -> Hook Element) -> ReaderT React JSM (Component JSVal ())
|
||||
component :: FromJSVal props => (props -> Hook Element) -> ReaderT React JSM (Component props ())
|
||||
component hook = do
|
||||
react <- ask
|
||||
f <- lift $ function' $ \_ _ args -> flip runReaderT react $ do
|
||||
let props = case args of
|
||||
let propsVal = case args of
|
||||
[] -> jsUndefined
|
||||
arg0 : _ -> arg0
|
||||
props <- liftJSM $ fromJSVal propsVal >>= \case
|
||||
Nothing -> fail "Invalid props"
|
||||
Just props -> pure props
|
||||
e <- unHook $ hook props
|
||||
unElement e
|
||||
pure $ Component f
|
||||
|
Loading…
Reference in New Issue
Block a user