From 141b482739d12657a19caf5b671aa1cab4b11ef3 Mon Sep 17 00:00:00 2001 From: Ryan Trinkle Date: Tue, 4 Jul 2023 12:50:17 -0400 Subject: [PATCH] Get rid of `Render` monad; make components look more like JS components --- src/React/Component.hs | 7 +++---- src/React/Types.hs | 10 ---------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/React/Component.hs b/src/React/Component.hs index 4431053..aea92e1 100644 --- a/src/React/Component.hs +++ b/src/React/Component.hs @@ -9,15 +9,14 @@ 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 :: Hook (JSVal -> Render Element) -> ReaderT React JSM (Component JSVal ()) -component (Hook hook) = do +component :: (JSVal -> Hook Element) -> ReaderT React JSM (Component JSVal ()) +component hook = do react <- ask f <- lift $ function' $ \_ _ args -> flip runReaderT react $ do - render <- hook let props = case args of [] -> jsUndefined arg0 : _ -> arg0 - e <- unRender $ render props + e <- unHook $ hook props unElement e pure $ Component f diff --git a/src/React/Types.hs b/src/React/Types.hs index 01e5389..d66e8fe 100644 --- a/src/React/Types.hs +++ b/src/React/Types.hs @@ -31,16 +31,6 @@ newtype Hook a = Hook { unHook :: ReaderT React JSM a } #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 } instance IsString Element where