on develop help sign in
WIP
9466d90Oliver Batchelor
reflex.cabal+1−1
@@ -285,7 +285,7 @@ test-suite DebugCycles
285 , witherable
285 , witherable
286
286
287 if flag(split-these)
287 if flag(split-these)
288− build-depends: these-lens
288+ build-depends: these-lens, semialign
289
289
290 other-modules:
290 other-modules:
291 Test.Run
291 Test.Run
test/DebugCycles.hs+36−1
@@ -13,6 +13,7 @@ import Control.Monad.Fix
13import Data.Functor.Misc
13import Data.Functor.Misc
14import qualified Data.Map as M
14import qualified Data.Map as M
15import Data.These
15import Data.These
16+import Data.Align
16
17
17
18
18import Reflex
19import Reflex
@@ -41,14 +42,48 @@ dynLoop (e1, e2) = do
41 return $ updated d'
42 return $ updated d'
42
43
43
44
45+connectButtonPromptly :: (MonadHold t m, Reflex t, MonadFix m) => Event t () -> Event t a -> m (Event t a)
46+connectButtonPromptly click e = do
47+ d <- holdDyn never (e <$ click)
48+ return (switchDyn d)
49+
50+connectButton :: (MonadHold t m, Reflex t, MonadFix m) => Event t () -> Event t a -> m (Event t a)
51+connectButton click e = do
52+ d <- hold never (e <$ click)
53+ return (switch d)
54+
55+
56+switchLoop :: (MonadHold t m, Reflex t, MonadFix m) => (Event t Int, Event t ()) -> m (Event t Int)
57+switchLoop (e1, e2) = do
58+ rec
59+ e' <- connectButton e2 (updated d)
60+ d <- count (align e' e1)
61+
62+ return $ updated d
63+
64+staticLoop :: AppWidget t m => m ()
65+staticLoop = do
66+ el "p" $ do
67+ text "Typical error: GHC stack-space overflow: current limit is 33624 bytes"
68+ text "(or consumes all available memory)"
69+
70+ e <- getPostBuild
71+ rec
72+ d <- foldDyn (+) (0 :: Int) (leftmost [1 <$ e, updated d])
73+ dynText (T.pack . show <$> d)
74+
75+
76+
44splitThese :: Filterable f => f (These a b) -> (f a, f b)
77splitThese :: Filterable f => f (These a b) -> (f a, f b)
45splitThese f = (mapMaybe (preview here) f, mapMaybe (preview there) f)
78splitThese f = (mapMaybe (preview here) f, mapMaybe (preview there) f)
46
79
47main :: IO ()
80main :: IO ()
48main = void $ do
81main = void $ do
82+
83+ runApp' (switchLoop . splitThese) (Just <$> occs)
49 runApp' (dynLoop . splitThese) (Just <$> occs)
84 runApp' (dynLoop . splitThese) (Just <$> occs)
50
85
51 where
86 where
52− occs = [ This 1, This 2, That (), This 3 ]
87+ occs = [ This 1, This 2, That (), This 3 ]
53
88
54
89