{-# LANGUAGE CPP #-}
{-# LANGUAGE MultiParamTypeClasses #-}
#ifdef USE_REFLEX_OPTIMIZER
{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
#endif
module Reflex.Network
( networkView
, networkHold
, untilReady
) where
import Reflex.Class
import Reflex.Adjustable.Class
import Reflex.NotReady.Class
import Reflex.PostBuild.Class
networkView :: (NotReady t m, Adjustable t m, PostBuild t m) => Dynamic t (m a) -> m (Event t a)
networkView child = do
postBuild <- getPostBuild
let newChild = leftmost [updated child, tagCheap (current child) postBuild]
snd <$> runWithReplace notReady newChild
networkHold :: (Adjustable t m, MonadHold t m) => m a -> Event t (m a) -> m (Dynamic t a)
networkHold child0 newChild = do
(result0, newResult) <- runWithReplace child0 newChild
holdDyn result0 newResult
untilReady :: (Adjustable t m, PostBuild t m) => m a -> m b -> m (a, Event t b)
untilReady a b = do
postBuild <- getPostBuild
runWithReplace a $ b <$ postBuild