1-- | This module defines 'TriggerEvent', which describes actions that may create
2-- new 'Event's that can be triggered from 'IO'.
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FunctionalDependencies #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE UndecidableInstances #-}
7module Reflex.TriggerEvent.Class
13import Control.Monad.Reader
14import Control.Monad.State
15import qualified Control.Monad.State.Strict as Strict
17--TODO: Shouldn't have IO hard-coded
18-- | 'TriggerEvent' represents actions that can create 'Event's that can be
19-- triggered by 'IO' actions.
20class Monad m => TriggerEvent t m | m -> t where
21 -- | Create a triggerable 'Event'. Whenever the resulting function is called,
22 -- the resulting 'Event' will fire at some point in the future. Note that
23 -- this may not be synchronous.
24 newTriggerEvent :: m (Event t a, a -> IO ())
25 -- | Like 'newTriggerEvent', but the callback itself takes another callback,
26 -- to be invoked once the requested 'Event' occurrence has finished firing.
27 -- This allows synchronous operation.
28 newTriggerEventWithOnComplete :: m (Event t a, a -> IO () -> IO ()) --TODO: This and newTriggerEvent should be unified somehow
29 -- | Like 'newTriggerEventWithOnComplete', but with setup and teardown. This
30 -- relatively complex type signature allows any external listeners to be
31 -- subscribed lazily and then removed whenever the returned 'Event' is no
32 -- longer being listened to. Note that the setup/teardown may happen multiple
33 -- times, and there is no guarantee that the teardown will be executed
34 -- promptly, or even at all, in the case of program termination.
35 newEventWithLazyTriggerWithOnComplete :: ((a -> IO () -> IO ()) -> IO (IO ())) -> m (Event t a)
37instance TriggerEvent t m => TriggerEvent t (ReaderT r m) where
38 newTriggerEvent = lift newTriggerEvent
39 newTriggerEventWithOnComplete = lift newTriggerEventWithOnComplete
40 newEventWithLazyTriggerWithOnComplete = lift . newEventWithLazyTriggerWithOnComplete
42instance TriggerEvent t m => TriggerEvent t (StateT s m) where
43 newTriggerEvent = lift newTriggerEvent
44 newTriggerEventWithOnComplete = lift newTriggerEventWithOnComplete
45 newEventWithLazyTriggerWithOnComplete = lift . newEventWithLazyTriggerWithOnComplete
47instance TriggerEvent t m => TriggerEvent t (Strict.StateT s m) where
48 newTriggerEvent = lift newTriggerEvent
49 newTriggerEventWithOnComplete = lift newTriggerEventWithOnComplete
50 newEventWithLazyTriggerWithOnComplete = lift . newEventWithLazyTriggerWithOnComplete
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