on develop help sign in
Add untilReady
commit706ab47df9729bdc5c4ac3f4d8dfd4661d9f6e1a authorRyan Trinkle <ryan.trinkle@gmail.com> dateWed 10 May 2017, 19:39 (9 years ago) parentf9427da
2 files changed+13−4
reflex-dom-core/src/Reflex/Dom/Widget/Basic.hs+8 test/prebuild.hs+5−4
reflex-dom-core/src/Reflex/Dom/Widget/Basic.hs+8
@@ -22,6 +22,7 @@ module Reflex.Dom.Widget.Basic
2222 , button
2323 , dyn
2424 , widgetHold
25+ , untilReady
2526
2627 -- * Working with Maps
2728 , diffMapNoEq
@@ -172,6 +173,13 @@ widgetHold child0 newChild = do
172173 (result0, newResult) <- widgetHoldInternal child0 newChild
173174 holdDyn result0 newResult
174175
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+
175183diffMapNoEq :: (Ord k) => Map k v -> Map k v -> Map k (Maybe v)
176184diffMapNoEq olds news = flip Map.mapMaybe (align olds news) $ \case
177185 This _ -> Just Nothing
test/prebuild.hs+5−4
@@ -37,7 +37,7 @@ w = do
3737 _ <- widgetHold (text "Starting") $ text . T.pack . show <$> n
3838 return ()
3939 -}
40− {- Many dyns
40+-- {- Many dyns
4141 slow = elAttr "div" ("style" =: "position:relative;width:256px;height:256px") $ go maxDepth
4242 where maxDepth = 6 :: Int
4343 go 0 = blank
@@ -48,7 +48,7 @@ w = do
4848 elAttr "div" ("style" =: s "left:50%;right:0;top:0;bottom:50%") $ go $ pred n
4949 elAttr "div" ("style" =: s "left:50%;right:0;top:50%;bottom:0") $ go $ pred n
5050 elAttr "div" ("style" =: s "left:0;right:50%;top:50%;bottom:0") $ go $ pred n
51− -}
51+-- -}
5252 {- Many elDynAttrs
5353 slow = do
5454 let size = 64
@@ -94,6 +94,7 @@ w = do
9494 traverseDMapWithKeyWithAdjustWithMove f (DMap.singleton LeftTag $ Const2 ()) $ (PatchDMapWithMove.moveDMapKey LeftTag RightTag) <$ postBuild
9595 return ()
9696 -}
97+ {-
9798 slow = do
9899 let h x = do
99100 liftIO $ putStrLn "render hook"
@@ -110,11 +111,11 @@ w = do
110111 postBuild <- getPostBuild
111112 _ <- traverseDMapWithKeyWithAdjust f mempty $ PatchDMap (DMap.singleton (Const2 () :: Const2 () () ()) (ComposeMaybe $ Just $ Identity ())) <$ postBuild
112113 return ()
114+ -}
113115 el "div" $ do
114116 draw <- button "Draw"
115117 widgetHold blank $ ffor draw $ \_ -> do
116− postBuild <- getPostBuild
117− widgetHold (text "Loading...") $ slow <$ postBuild
118+ _ <- untilReady (text "Loading...") slow
118119 return ()
119120 return ()
120121