@@ -23,6 +23,10 @@ import Data.Functor.Misc
23import qualified Data.Map as Map
23import qualified Data.Map as Map
24import Data.Map (Map)
24import Data.Map (Map)
26+import qualified Data.IntMap as IntMap
27+import Data.IntMap (IntMap)
26import Data.These
30import Data.These
27import Data.Align
31import Data.Align
@@ -41,6 +45,7 @@ import Data.These.Lens
42type Widget t m = (MonadHold t m, Reflex t, MonadFix m)
46type Widget t m = (MonadHold t m, Reflex t, MonadFix m)
44connectDyn ::Widget t m => Event t () -> (Dynamic t a, Dynamic t a) -> m (Dynamic t a)
49connectDyn ::Widget t m => Event t () -> (Dynamic t a, Dynamic t a) -> m (Dynamic t a)
45connectDyn e (d, d') = do
50connectDyn e (d, d') = do
46 dd <- holdDyn d (d' <$ e)
51 dd <- holdDyn d (d' <$ e)
@@ -78,7 +83,7 @@ addHeight e = leftmost [e4, e4] where
78 e4 = leftmost [e3, e3]
83 e4 = leftmost [e3, e3]
81−-- Take an existing test and build it inside a push
86+-- Take an existing test and build it inside a
82buildLoop :: Widget t m => (forall t m. Widget t m => (Event t Int, Event t ()) -> m (Event t Int)) -> (Event t Int, Event t ()) -> m (Event t Int)
87buildLoop :: Widget t m => (forall t m. Widget t m => (Event t Int, Event t ()) -> m (Event t Int)) -> (Event t Int, Event t ()) -> m (Event t Int)
83buildLoop test (e1, e2) = switchHold never buildLoop
88buildLoop test (e1, e2) = switchHold never buildLoop
84 where buildLoop = pushAlways (const $ test (e1, e2)) e2
89 where buildLoop = pushAlways (const $ test (e1, e2)) e2
@@ -99,9 +104,25 @@ switchLoop :: Widget t m => (Event t Int, Event t ()) -> m (Event t Int)
99switchLoop (e1, e2) = do
104switchLoop (e1, e2) = do
101 e' <- connectButton e2 (updated d)
106 e' <- connectButton e2 (updated d)
102− d <- count (align e' (addHeight e1))
107+ d <- count (align e' e1)
103 return $ updated d
108 return $ updated d
110+mergeLoop :: forall t m. (Adjustable t m, Widget t m) => (Event t Int, Event t ()) -> m (Event t Int)
111+mergeLoop (e1, e2) = do
113+ (_, e) <- runEventWriterT $
114+ runWithReplace w (leftmost [w <$ e1])
121+ tellEvent (updated ((pure <$> c) :: Dynamic t [Int]))
105switchLoop' :: Widget t m => (Event t Int, Event t ()) -> m (Event t Int)
126switchLoop' :: Widget t m => (Event t Int, Event t ()) -> m (Event t Int)
106switchLoop' (e1, e2) = do
127switchLoop' (e1, e2) = do
@@ -152,20 +173,25 @@ runTest (name, TestCase test) = do
155− run = runApp' (test . splitThese) (Just <$> occs)
177+ r <- runApp' (test . splitThese) (Just <$> occs)
156− >> error (name <> ": unexpected success")
178+ error (name <> ": unexpected success " <> show r)
158− occs = [ That (), This 3, That (), This 4 ]
180+ occs = [ This 1, This 2, That (), This 3, That (), This 1 ]
160 milliseconds = (*1000)
182 milliseconds = (*1000)
163−newtype TestCase = TestCase { unTest :: forall t m. Widget t m => (Event t Int, Event t ()) -> m (Event t Int) }
185+newtype TestCase = TestCase { unTest :: forall t m. (Widget t m, Adjustable t m) => (Event t Int, Event t ()) -> m (Event t Int) }
165tests :: [(String, TestCase)]
187tests :: [(String, TestCase)]
167 [ ("switchLoop'", TestCase switchLoop')
189 [ ("switchLoop'", TestCase switchLoop')
168− --, ("switchLoop", TestCase switchLoop)
190+ , ("switchLoop", TestCase switchLoop)
192+ , ("mergeLoop", TestCase mergeLoop)
169 -- , ("switchLoop2", TestCase switchLoop2)
195 -- , ("switchLoop2", TestCase switchLoop2)
171 -- , ("staticLoop'", TestCase staticLoop')
197 -- , ("staticLoop'", TestCase staticLoop')