1
+ {-# LANGUAGE AllowAmbiguousTypes #-}
1
2
{-# LANGUAGE CPP #-}
2
3
{-# LANGUAGE BangPatterns #-}
3
4
{-# LANGUAGE FlexibleContexts #-}
@@ -17,7 +18,7 @@ import Control.Lens hiding (has)
17
18
import Control.Monad
18
19
import Control.Monad.Fail (MonadFail )
19
20
import Control.Monad.Fix
20
- import Control.Monad.IO.Class (MonadIO , liftIO )
21
+ import Control.Monad.IO.Class (MonadIO )
21
22
import Control.Monad.Primitive
22
23
import Data.Constraint.Extras
23
24
import Data.Constraint.Extras.TH
@@ -70,6 +71,8 @@ main = do
70
71
print os7
71
72
os8 <- runApp' testMatchRequestsWithResponses [ Just $ TestRequest_Reverse " abcd" ]
72
73
print os8
74
+ os9 <- runApp' testMoribundPerformEvent $ map Just [ 1 .. 3 ]
75
+ print os9
73
76
let ! [[Just [10 ,9 ,8 ,7 ,6 ,5 ,4 ,3 ,2 ,1 ]]] = os1
74
77
let ! [[Just [1 ,3 ,5 ,7 ,9 ]],[Nothing ,Nothing ],[Just [2 ,4 ,6 ,8 ,10 ]],[Just [2 ,4 ,6 ,8 ,10 ],Nothing ]] = os2
75
78
let ! [[Nothing , Just [2 ]]] = os3
@@ -78,6 +81,7 @@ main = do
78
81
let ! [[Nothing , Nothing ]] = os6 -- TODO re-enable this test after issue #233 has been resolved
79
82
let ! (Just [(- 9223372036854775808 ," 2" )]) = M. toList <$> head (head os7)
80
83
let ! (Just [(- 9223372036854775808 ," dcba" )]) = M. toList <$> head (head os8)
84
+ let ! [[Nothing ,Just " 0:1" ],[Nothing ,Just " 1:2" ],[Nothing ,Just " 2:3" ]] = os9
81
85
return ()
82
86
83
87
unwrapApp :: forall t m a .
@@ -203,6 +207,11 @@ data TestRequest a where
203
207
TestRequest_Reverse :: String -> TestRequest String
204
208
TestRequest_Increment :: Int -> TestRequest Int
205
209
210
+ instance Show (TestRequest a ) where
211
+ show = \ case
212
+ TestRequest_Reverse str -> " reverse " <> str
213
+ TestRequest_Increment i -> " increment " <> show i
214
+
206
215
testMatchRequestsWithResponses
207
216
:: forall m t req a
208
217
. ( MonadFix m
@@ -234,9 +243,23 @@ testMatchRequestsWithResponses pulse = mdo
234
243
, \ x -> has @ Read r $ readMaybe x
235
244
)
236
245
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
238
263
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