1{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE RecursiveDo #-}
4{-# LANGUAGE ScopedTypeVariables #-}
9import Control.Monad.Fix
10import qualified Data.Dependent.Map as DMap
11import Data.Functor.Misc
12import qualified Data.Map as M
16import Reflex.EventWriter.Base
21 os1@[[Just [10,9,8,7,6,5,4,3,2,1]]] <- runApp' (unwrapApp testOrdering) $
25 os2@[[Just [1,3,5,7,9]],[Nothing,Nothing],[Just [2,4,6,8,10]],[Just [2,4,6,8,10],Nothing]]
26 <- runApp' (unwrapApp testSimultaneous) $ map Just $
33 os3@[[Nothing, Just [2]]] <- runApp' (unwrapApp testMoribundTellEvent) [Just ()]
35 os4@[[Nothing, Just [2]]] <- runApp' (unwrapApp testMoribundTellEventDMap) [Just ()]
37 os5@[[Nothing, Just [1, 2]]] <- runApp' (unwrapApp testLiveTellEventDMap) [Just ()]
41unwrapApp :: (Reflex t, Monad m) => (a -> EventWriterT t [Int] m ()) -> a -> m (Event t [Int])
43 ((), e) <- runEventWriterT $ x appIn
46testOrdering :: (Reflex t, Monad m) => Event t () -> EventWriterT t [Int] m ()
47testOrdering pulse = do
48 forM_ [10,9..1] $ \i -> tellEvent ([i] <$ pulse)
51testSimultaneous :: (Reflex t, Adjustable t m, MonadHold t m) => Event t (These () ()) -> EventWriterT t [Int] m ()
52testSimultaneous pulse = do
53 let e0 = fmapMaybe (^? here) pulse
54 e1 = fmapMaybe (^? there) pulse
55 forM_ [1,3..9] $ \i -> runWithReplace (tellEvent ([i] <$ e0)) $ ffor e1 $ \_ -> tellEvent ([i+1] <$ e0)
58-- | Test that a widget telling and event which fires at the same time it has been replaced
59-- doesn't count along with the new widget.
68 -> EventWriterT t [Int] m ()
69testMoribundTellEvent pulse = do
70 rec let tellIntOnReplace :: Int -> EventWriterT t [Int] m ()
71 tellIntOnReplace x = tellEvent $ [x] <$ rwrFinished
72 (_, rwrFinished) <- runWithReplace (tellIntOnReplace 1) $ tellIntOnReplace 2 <$ pulse
75-- | The equivalent of 'testMoribundTellEvent' for 'traverseDMapWithKeyWithAdjust'.
76testMoribundTellEventDMap
84 -> EventWriterT t [Int] m ()
85testMoribundTellEventDMap pulse = do
86 rec let tellIntOnReplace :: Int -> EventWriterT t [Int] m ()
87 tellIntOnReplace x = tellEvent $ [x] <$ rwrFinished
88 (_, rwrFinished :: Event t (PatchDMap (Const2 () Int) Identity)) <-
89 traverseDMapWithKeyWithAdjust
90 (\(Const2 ()) (Identity v) -> Identity . const v <$> tellIntOnReplace v)
91 (mapToDMap $ M.singleton () 1)
92 ((PatchDMap $ DMap.map (ComposeMaybe . Just) $ mapToDMap $ M.singleton () 2) <$ pulse)
95-- | Ensures that elements which are _not_ removed can still fire 'tellEvent's
96-- during the same frame as other elements are updated.
105 -> EventWriterT t [Int] m ()
106testLiveTellEventDMap pulse = do
107 rec let tellIntOnReplace :: Int -> EventWriterT t [Int] m ()
108 tellIntOnReplace x = tellEvent $ [x] <$ rwrFinished
109 (_, rwrFinished :: Event t (PatchDMap (Const2 Int ()) Identity)) <-
110 traverseDMapWithKeyWithAdjust
111 (\(Const2 k) (Identity ()) -> Identity <$> tellIntOnReplace k)
112 (mapToDMap $ M.singleton 1 ())
113 ((PatchDMap $ DMap.map (ComposeMaybe . Just) $ mapToDMap $ M.singleton 2 ()) <$ 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