1{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE RecursiveDo #-}
5{-# LANGUAGE ScopedTypeVariables #-}
10import Control.Monad.Fix
11import qualified Data.Dependent.Map as DMap
12import Data.Functor.Misc
13import qualified Data.Map as M
17import Reflex.EventWriter.Base
22 os1@[[Just [10,9,8,7,6,5,4,3,2,1]]] <- runApp' (unwrapApp testOrdering) $
26 os2@[[Just [1,3,5,7,9]],[Nothing,Nothing],[Just [2,4,6,8,10]],[Just [2,4,6,8,10],Nothing]]
27 <- runApp' (unwrapApp testSimultaneous) $ map Just $
34 os3@[[Nothing, Just [2]]] <- runApp' (unwrapApp testMoribundTellEvent) [Just ()]
36 os4@[[Nothing, Just [2]]] <- runApp' (unwrapApp testMoribundTellEventDMap) [Just ()]
38 os5@[[Nothing, Just [1, 2]]] <- runApp' (unwrapApp testLiveTellEventDMap) [Just ()]
40 os6 <- runApp' (unwrapApp delayedPulse) [Just ()]
42 let ![[Nothing, Nothing]] = os6
45unwrapApp :: (Reflex t, Monad m) => (a -> EventWriterT t [Int] m ()) -> a -> m (Event t [Int])
47 ((), e) <- runEventWriterT $ x appIn
50testOrdering :: (Reflex t, Monad m) => Event t () -> EventWriterT t [Int] m ()
51testOrdering pulse = do
52 forM_ [10,9..1] $ \i -> tellEvent ([i] <$ pulse)
55testSimultaneous :: (Reflex t, Adjustable t m, MonadHold t m) => Event t (These () ()) -> EventWriterT t [Int] m ()
56testSimultaneous pulse = do
57 let e0 = fmapMaybe (^? here) pulse
58 e1 = fmapMaybe (^? there) pulse
59 forM_ [1,3..9] $ \i -> runWithReplace (tellEvent ([i] <$ e0)) $ ffor e1 $ \_ -> tellEvent ([i+1] <$ e0)
62-- | Test that a widget telling and event which fires at the same time it has been replaced
63-- doesn't count along with the new widget.
72 -> EventWriterT t [Int] m ()
73testMoribundTellEvent pulse = do
74 rec let tellIntOnReplace :: Int -> EventWriterT t [Int] m ()
75 tellIntOnReplace x = tellEvent $ [x] <$ rwrFinished
76 (_, rwrFinished) <- runWithReplace (tellIntOnReplace 1) $ tellIntOnReplace 2 <$ pulse
79-- | The equivalent of 'testMoribundTellEvent' for 'traverseDMapWithKeyWithAdjust'.
80testMoribundTellEventDMap
88 -> EventWriterT t [Int] m ()
89testMoribundTellEventDMap pulse = do
90 rec let tellIntOnReplace :: Int -> EventWriterT t [Int] m ()
91 tellIntOnReplace x = tellEvent $ [x] <$ rwrFinished
92 (_, rwrFinished :: Event t (PatchDMap (Const2 () Int) Identity)) <-
93 traverseDMapWithKeyWithAdjust
94 (\(Const2 ()) (Identity v) -> Identity . const v <$> tellIntOnReplace v)
95 (mapToDMap $ M.singleton () 1)
96 ((PatchDMap $ DMap.map (ComposeMaybe . Just) $ mapToDMap $ M.singleton () 2) <$ pulse)
99-- | Ensures that elements which are _not_ removed can still fire 'tellEvent's
100-- during the same frame as other elements are updated.
109 -> EventWriterT t [Int] m ()
110testLiveTellEventDMap pulse = do
111 rec let tellIntOnReplace :: Int -> EventWriterT t [Int] m ()
112 tellIntOnReplace x = tellEvent $ [x] <$ rwrFinished
113 (_, rwrFinished :: Event t (PatchDMap (Const2 Int ()) Identity)) <-
114 traverseDMapWithKeyWithAdjust
115 (\(Const2 k) (Identity ()) -> Identity <$> tellIntOnReplace k)
116 (mapToDMap $ M.singleton 1 ())
117 ((PatchDMap $ DMap.map (ComposeMaybe . Just) $ mapToDMap $ M.singleton 2 ()) <$ pulse)
128 -> EventWriterT t [Int] m ()
129delayedPulse pulse = void $ flip runWithReplace (pure () <$ pulse) $ do
130 -- This has the effect of delaying pulse' from pulse
131 (_, pulse') <- runWithReplace (pure ()) $ pure [1] <$ pulse
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list