1{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE RankNTypes #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE TypeFamilies #-}
10import Control.Monad.IO.Class
11import Control.Monad.Ref
13import Data.Dependent.Map (DMap)
14import qualified Data.Dependent.Map as DMap
15import Data.Dependent.Sum
16import Data.Functor.Identity
17import Data.GADT.Compare
22import Data.Functor.Misc
25import qualified Reflex.Host.Class as Host
26import qualified Reflex.Spider.Internal as S
33 ref <- newIORef Nothing
35 readIORef ref >>= maybe exitFailure (putStrLn . ("Result " <>) . show)
37hostPerf :: IORef (Maybe Int) -> IO ()
38hostPerf ref = S.runSpiderHost $ do
40 liftIO $ putStrLn "#creating triggers"
41 (response', responseTrigger) <- Host.newEventWithTriggerRef
42 (eadd', addTriggerRef) <- Host.newEventWithTriggerRef
43 let response = S.unSpiderEvent response'
44 eadd = S.unSpiderEvent eadd'
45 liftIO $ putStrLn "#creating event graph"
46 eventToPerform <- Host.runHostFrame $ do
47 (reqMap :: S.Event S.Global (DMap (Const2 Int (DMap Tell (S.SpiderHostFrame S.Global))) Identity))
52 -- Construct a new heap object for the subscriber, invalidating any weak references to the subscriber if they are not retained
53 $ (\e -> S.Event $ \sub -> do
54 (s, o) <- S.subscribeAndRead e $ sub
55 { S.subscriberPropagate = S.subscriberPropagate sub
58 $ runIdentity <$> S.select
59 (S.fan $ S.pushCheap (return . Just . mapKeyValuePairsMonotonic (\(t :=> e) -> WrapArg t :=> Identity e)) response)
61 return $ alignWith (mergeThese (<>))
62 (flip S.pushCheap eadd $ \_ -> return $ Just $ DMap.singleton Request $ do
63 liftIO $ putStrLn "#eadd fired"
64 return $ PatchDMap $ DMap.singleton (Const2 (1 :: Int)) $ ComposeMaybe $ Just
65 $ S.pushCheap (return . Just . DMap.singleton Action . (\_ -> liftIO (writeIORef ref (Just 1)))) $ eadd)
66 (flip S.pushCheap reqMap $ \m -> return $ Just $ mconcat $ (\(Const2 _ :=> Identity reqs) -> reqs) <$> DMap.toList m)
68 eventToPerformHandle <- Host.subscribeEvent (S.SpiderEvent eventToPerform)
69 liftIO $ putStrLn "#performing GC" >> performMajorGC
70 liftIO $ putStrLn "#attempting to fire eadd"
71 mAddTrigger <- readRef addTriggerRef
72 forM_ mAddTrigger $ \t -> replicateM_ 2 $ do
73 liftIO $ putStrLn "#firing eadd"
74 mToPerform <- Host.fireEventsAndRead [t :=> Identity ()] $ sequence =<< Host.readEvent eventToPerformHandle
78 responses <- Host.runHostFrame $ DMap.traverseWithKey (\_ v -> Identity <$> v) toPerform
79 mrt <- readRef responseTrigger
80 let followupEventTriggers = case mrt of
81 Just rt -> [rt :=> Identity responses]
83 Host.fireEventsAndRead followupEventTriggers $ return ()
89 Request :: Tell (PatchDMap (Const2 Int (DMap Tell (S.SpiderHostFrame S.Global))) (S.Event S.Global))
91instance GEq Tell where
92 geq Action Action = Just Refl
93 geq Request Request = Just Refl
96instance GCompare Tell where
97 gcompare Action Action = GEQ
98 gcompare Request Request = GEQ
99 gcompare Action Request = GLT
100 gcompare Request Action = GGT
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