on baac813 help sign in
patch/src/Reflex/Network.hs
39 lines 1.8 kB history raw
1{-# LANGUAGE CPP #-}
2{-# LANGUAGE MultiParamTypeClasses #-}
3#ifdef USE_REFLEX_OPTIMIZER
4{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
5#endif
6module Reflex.Network
7 ( networkView
8 , networkHold
9 , untilReady
10 ) where
12import Reflex.Class
13import Reflex.Adjustable.Class
14import Reflex.NotReady.Class
15import Reflex.PostBuild.Class
17-- | Given a Dynamic of network-creating actions, create a network that is recreated whenever the Dynamic updates.
18-- The returned Event of network results occurs when the Dynamic does.
19-- Note: Often, the type 'a' is an Event, in which case the return value is an Event-of-Events that would typically be flattened (via 'switchPromptly').
20networkView :: (NotReady t m, Adjustable t m, PostBuild t m) => Dynamic t (m a) -> m (Event t a)
21networkView child = do
22 postBuild <- getPostBuild
23 let newChild = leftmost [updated child, tagCheap (current child) postBuild]
24 snd <$> runWithReplace notReady newChild
26-- | Given an initial network and an Event of network-creating actions, create a network that is recreated whenever the Event fires.
27-- The returned Dynamic of network results occurs when the Event does.
28-- Note: Often, the type 'a' is an Event, in which case the return value is a Dynamic-of-Events that would typically be flattened.
29networkHold :: (Adjustable t m, MonadHold t m) => m a -> Event t (m a) -> m (Dynamic t a)
30networkHold child0 newChild = do
31 (result0, newResult) <- runWithReplace child0 newChild
32 holdDyn result0 newResult
34-- | Render a placeholder network to be shown while another network is not yet
35-- done building
36untilReady :: (Adjustable t m, PostBuild t m) => m a -> m b -> m (a, Event t b)
37untilReady a b = do
38 postBuild <- getPostBuild
39 runWithReplace a $ b <$ postBuild