on develop help sign in
Add untilReady
706ab47Ryan Trinkle
reflex-dom-core/src/Reflex/Dom/Widget/Basic.hs+8
@@ -22,6 +22,7 @@ module Reflex.Dom.Widget.Basic
22 , button
22 , button
23 , dyn
23 , dyn
24 , widgetHold
24 , widgetHold
25+ , untilReady
25
26
26 -- * Working with Maps
27 -- * Working with Maps
27 , diffMapNoEq
28 , diffMapNoEq
@@ -172,6 +173,13 @@ widgetHold child0 newChild = do
172 (result0, newResult) <- widgetHoldInternal child0 newChild
173 (result0, newResult) <- widgetHoldInternal child0 newChild
173 holdDyn result0 newResult
174 holdDyn result0 newResult
174
175
176+-- | Render a placeholder widget to be shown while another widget is not yet
177+-- done rendering
178+untilReady :: (DomBuilder t m, PostBuild t m) => m a -> m b -> m (a, Event t b)
179+untilReady a b = do
180+ postBuild <- getPostBuild
181+ runWithReplace a $ b <$ postBuild
182+
175diffMapNoEq :: (Ord k) => Map k v -> Map k v -> Map k (Maybe v)
183diffMapNoEq :: (Ord k) => Map k v -> Map k v -> Map k (Maybe v)
176diffMapNoEq olds news = flip Map.mapMaybe (align olds news) $ \case
184diffMapNoEq olds news = flip Map.mapMaybe (align olds news) $ \case
177 This _ -> Just Nothing
185 This _ -> Just Nothing
test/prebuild.hs+5−4
@@ -37,7 +37,7 @@ w = do
37 _ <- widgetHold (text "Starting") $ text . T.pack . show <$> n
37 _ <- widgetHold (text "Starting") $ text . T.pack . show <$> n
38 return ()
38 return ()
39 -}
39 -}
40− {- Many dyns
40+-- {- Many dyns
41 slow = elAttr "div" ("style" =: "position:relative;width:256px;height:256px") $ go maxDepth
41 slow = elAttr "div" ("style" =: "position:relative;width:256px;height:256px") $ go maxDepth
42 where maxDepth = 6 :: Int
42 where maxDepth = 6 :: Int
43 go 0 = blank
43 go 0 = blank
@@ -48,7 +48,7 @@ w = do
48 elAttr "div" ("style" =: s "left:50%;right:0;top:0;bottom:50%") $ go $ pred n
48 elAttr "div" ("style" =: s "left:50%;right:0;top:0;bottom:50%") $ go $ pred n
49 elAttr "div" ("style" =: s "left:50%;right:0;top:50%;bottom:0") $ go $ pred n
49 elAttr "div" ("style" =: s "left:50%;right:0;top:50%;bottom:0") $ go $ pred n
50 elAttr "div" ("style" =: s "left:0;right:50%;top:50%;bottom:0") $ go $ pred n
50 elAttr "div" ("style" =: s "left:0;right:50%;top:50%;bottom:0") $ go $ pred n
51− -}
51+-- -}
52 {- Many elDynAttrs
52 {- Many elDynAttrs
53 slow = do
53 slow = do
54 let size = 64
54 let size = 64
@@ -94,6 +94,7 @@ w = do
94 traverseDMapWithKeyWithAdjustWithMove f (DMap.singleton LeftTag $ Const2 ()) $ (PatchDMapWithMove.moveDMapKey LeftTag RightTag) <$ postBuild
94 traverseDMapWithKeyWithAdjustWithMove f (DMap.singleton LeftTag $ Const2 ()) $ (PatchDMapWithMove.moveDMapKey LeftTag RightTag) <$ postBuild
95 return ()
95 return ()
96 -}
96 -}
97+ {-
97 slow = do
98 slow = do
98 let h x = do
99 let h x = do
99 liftIO $ putStrLn "render hook"
100 liftIO $ putStrLn "render hook"
@@ -110,11 +111,11 @@ w = do
110 postBuild <- getPostBuild
111 postBuild <- getPostBuild
111 _ <- traverseDMapWithKeyWithAdjust f mempty $ PatchDMap (DMap.singleton (Const2 () :: Const2 () () ()) (ComposeMaybe $ Just $ Identity ())) <$ postBuild
112 _ <- traverseDMapWithKeyWithAdjust f mempty $ PatchDMap (DMap.singleton (Const2 () :: Const2 () () ()) (ComposeMaybe $ Just $ Identity ())) <$ postBuild
112 return ()
113 return ()
114+ -}
113 el "div" $ do
115 el "div" $ do
114 draw <- button "Draw"
116 draw <- button "Draw"
115 widgetHold blank $ ffor draw $ \_ -> do
117 widgetHold blank $ ffor draw $ \_ -> do
116− postBuild <- getPostBuild
117− widgetHold (text "Loading...") $ slow <$ postBuild
118+ _ <- untilReady (text "Loading...") slow
118 return ()
119 return ()
119 return ()
120 return ()
120
121