Get rid of Render
monad; make components look more like JS components
This commit is contained in:
parent
aa5d40a625
commit
141b482739
@ -9,15 +9,14 @@ import React.JSaddle
|
|||||||
import React.Types
|
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
|
--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 :: Hook (JSVal -> Render Element) -> ReaderT React JSM (Component JSVal ())
|
component :: (JSVal -> Hook Element) -> ReaderT React JSM (Component JSVal ())
|
||||||
component (Hook hook) = do
|
component hook = do
|
||||||
react <- ask
|
react <- ask
|
||||||
f <- lift $ function' $ \_ _ args -> flip runReaderT react $ do
|
f <- lift $ function' $ \_ _ args -> flip runReaderT react $ do
|
||||||
render <- hook
|
|
||||||
let props = case args of
|
let props = case args of
|
||||||
[] -> jsUndefined
|
[] -> jsUndefined
|
||||||
arg0 : _ -> arg0
|
arg0 : _ -> arg0
|
||||||
e <- unRender $ render props
|
e <- unHook $ hook props
|
||||||
unElement e
|
unElement e
|
||||||
pure $ Component f
|
pure $ Component f
|
||||||
|
|
||||||
|
@ -31,16 +31,6 @@ newtype Hook a = Hook { unHook :: ReaderT React JSM a }
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
|
|
||||||
newtype Render a = Render { unRender :: ReaderT React JSM a }
|
|
||||||
deriving ( Functor
|
|
||||||
, Applicative
|
|
||||||
, Monad
|
|
||||||
, MonadJSM
|
|
||||||
#ifndef ghcjs_HOST_OS
|
|
||||||
, MonadIO
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
|
|
||||||
newtype Element = Element { unElement :: ReaderT React JSM JSVal }
|
newtype Element = Element { unElement :: ReaderT React JSM JSVal }
|
||||||
|
|
||||||
instance IsString Element where
|
instance IsString Element where
|
||||||
|
Loading…
Reference in New Issue
Block a user