diff options
Diffstat (limited to 'client/src/Util')
-rw-r--r-- | client/src/Util/Reflex.hs (renamed from client/src/Util/Dom.hs) | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/client/src/Util/Dom.hs b/client/src/Util/Reflex.hs index 55b8521..c14feeb 100644 --- a/client/src/Util/Dom.hs +++ b/client/src/Util/Reflex.hs @@ -1,8 +1,9 @@ -module Util.Dom - ( divIfDyn - , divIfEvent +module Util.Reflex + ( visibleIfDyn + , visibleIfEvent , divVisibleIf , divClassVisibleIf + , flatten , getBody ) where @@ -15,17 +16,18 @@ import GHCJS.DOM.Types (Element) import Reflex.Dom (Dynamic, Event, MonadWidget) import qualified Reflex.Dom as R -divIfDyn :: forall t m a. MonadWidget t m => Dynamic t Bool -> m a -> m a -> m (Dynamic t a) -divIfDyn cond = divIfEvent (R.updated cond) +visibleIfDyn :: forall t m a. MonadWidget t m => Dynamic t Bool -> m a -> m a -> m (Event t a) +visibleIfDyn cond empty content = + R.dyn $ R.ffor cond $ \case + True -> content + False -> empty -divIfEvent :: forall t m a. MonadWidget t m => Event t Bool -> m a -> m a -> m (Dynamic t a) -divIfEvent cond empty content = - R.widgetHold empty (flip fmap cond (\show -> - if show - then - content - else - empty)) +visibleIfEvent :: forall t m a. MonadWidget t m => Event t Bool -> m a -> m a -> m (Dynamic t a) +visibleIfEvent cond empty content = + R.widgetHold empty $ + R.ffor cond $ \case + True -> content + False -> empty divVisibleIf :: forall t m a. MonadWidget t m => Dynamic t Bool -> m a -> m a divVisibleIf cond content = divClassVisibleIf cond "" content @@ -37,6 +39,11 @@ divClassVisibleIf cond className content = (fmap (\c -> (M.singleton "class" className) `M.union` if c then M.empty else M.singleton "style" "display:none") cond) content +flatten :: forall t m a. MonadWidget t m => Event t (Event t a) -> m (Event t a) +flatten e = do + dyn <- R.holdDyn R.never e + return $ R.switchDyn dyn + getBody :: forall t m. MonadWidget t m => m Element getBody = do document <- Dom.currentDocumentUnchecked |