1+ {-# LANGUAGE AllowAmbiguousTypes #-}
12{-# LANGUAGE CPP #-}
23{-# LANGUAGE BangPatterns #-}
34{-# LANGUAGE FlexibleContexts #-}
@@ -17,7 +18,7 @@ import Control.Lens hiding (has)
1718import Control.Monad
1819import Control.Monad.Fail (MonadFail )
1920import Control.Monad.Fix
20- import Control.Monad.IO.Class (MonadIO , liftIO )
21+ import Control.Monad.IO.Class (MonadIO )
2122import Control.Monad.Primitive
2223import Data.Constraint.Extras
2324import Data.Constraint.Extras.TH
@@ -70,6 +71,8 @@ main = do
7071 print os7
7172 os8 <- runApp' testMatchRequestsWithResponses [ Just $ TestRequest_Reverse " abcd" ]
7273 print os8
74+ os9 <- runApp' testMoribundPerformEvent $ map Just [ 1 .. 3 ]
75+ print os9
7376 let ! [[Just [10 ,9 ,8 ,7 ,6 ,5 ,4 ,3 ,2 ,1 ]]] = os1
7477 let ! [[Just [1 ,3 ,5 ,7 ,9 ]],[Nothing ,Nothing ],[Just [2 ,4 ,6 ,8 ,10 ]],[Just [2 ,4 ,6 ,8 ,10 ],Nothing ]] = os2
7578 let ! [[Nothing , Just [2 ]]] = os3
@@ -78,6 +81,7 @@ main = do
7881 let ! [[Nothing , Nothing ]] = os6 -- TODO re-enable this test after issue #233 has been resolved
7982 let ! (Just [(- 9223372036854775808 ," 2" )]) = M. toList <$> head (head os7)
8083 let ! (Just [(- 9223372036854775808 ," dcba" )]) = M. toList <$> head (head os8)
84+ let ! [[Nothing ,Just " 0:1" ],[Nothing ,Just " 1:2" ],[Nothing ,Just " 2:3" ]] = os9
8185 return ()
8286
8387unwrapApp :: forall t m a .
@@ -203,6 +207,11 @@ data TestRequest a where
203207 TestRequest_Reverse :: String -> TestRequest String
204208 TestRequest_Increment :: Int -> TestRequest Int
205209
210+ instance Show (TestRequest a ) where
211+ show = \ case
212+ TestRequest_Reverse str -> " reverse " <> str
213+ TestRequest_Increment i -> " increment " <> show i
214+
206215testMatchRequestsWithResponses
207216 :: forall m t req a
208217 . ( MonadFix m
@@ -234,9 +243,23 @@ testMatchRequestsWithResponses pulse = mdo
234243 , \ x -> has @ Read r $ readMaybe x
235244 )
236245
237- deriveArgDict ''TestRequest
246+ -- If a widget is destroyed, and simultaneously it tries to use performEvent, the event does not get performed.
247+ -- TODO Determine whether this is actually the behavior we want.
248+ testMoribundPerformEvent
249+ :: forall t m
250+ . ( Adjustable t m
251+ , PerformEvent t m
252+ , MonadHold t m
253+ , Reflex t
254+ )
255+ => Event t Int -> m (Event t String )
256+ testMoribundPerformEvent pulse = do
257+ (outputInitial, outputReplaced) <- runWithReplace (performPrint 0 pulse) $ ffor pulse $ \ i -> performPrint i pulse
258+ switchHold outputInitial outputReplaced
259+ where
260+ performPrint i evt =
261+ performEvent $ ffor evt $ \ output ->
262+ return $ show i <> " :" <> show output
238263
239- instance Show (TestRequest a ) where
240- show = \ case
241- TestRequest_Reverse str -> " reverse " <> str
242- TestRequest_Increment i -> " increment " <> show i
264+
265+ deriveArgDict ''TestRequest
0 commit comments