{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
#ifdef USE_REFLEX_OPTIMIZER
{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
#endif
module Reflex.Host.Class
( ReflexHost (..)
, MonadSubscribeEvent (..)
, MonadReadEvent (..)
, MonadReflexCreateTrigger (..)
, MonadReflexHost (..)
, fireEvents
, newEventWithTriggerRef
, fireEventRef
, fireEventRefAndRead
) where
import Reflex.Class
import Control.Monad.Fix
import Control.Monad.Identity
import Control.Monad.Ref
import Control.Monad.Trans
import Control.Monad.Trans.Cont (ContT)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Reader (ReaderT)
import Control.Monad.Trans.RWS (RWST)
import Control.Monad.Trans.State (StateT)
import qualified Control.Monad.Trans.State.Strict as Strict
import Control.Monad.Trans.Writer (WriterT)
import Data.Dependent.Sum (DSum (..))
import Data.GADT.Compare
class ( Reflex t
, MonadReflexCreateTrigger t (HostFrame t)
, MonadSample t (HostFrame t)
, MonadHold t (HostFrame t)
, MonadFix (HostFrame t)
, MonadSubscribeEvent t (HostFrame t)
) => ReflexHost t where
type EventTrigger t :: * -> *
type EventHandle t :: * -> *
type HostFrame t :: * -> *
class (Reflex t, Monad m) => MonadSubscribeEvent t m | m -> t where
subscribeEvent :: Event t a -> m (EventHandle t a)
class (ReflexHost t, Applicative m, Monad m) => MonadReadEvent t m | m -> t where
readEvent :: EventHandle t a -> m (Maybe (m a))
class (Applicative m, Monad m) => MonadReflexCreateTrigger t m | m -> t where
newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> m (Event t a)
newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> m (EventSelector t k)
class ( ReflexHost t
, MonadReflexCreateTrigger t m
, MonadSubscribeEvent t m
, MonadReadEvent t (ReadPhase m)
, MonadSample t (ReadPhase m)
, MonadHold t (ReadPhase m)
) => MonadReflexHost t m | m -> t where
type ReadPhase m :: * -> *
fireEventsAndRead :: [DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
runHostFrame :: HostFrame t a -> m a
fireEvents :: MonadReflexHost t m => [DSum (EventTrigger t) Identity] -> m ()
fireEvents :: [DSum (EventTrigger t) Identity] -> m ()
fireEvents dm :: [DSum (EventTrigger t) Identity]
dm = [DSum (EventTrigger t) Identity] -> ReadPhase m () -> m ()
forall t (m :: * -> *) a.
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
fireEventsAndRead [DSum (EventTrigger t) Identity]
dm (ReadPhase m () -> m ()) -> ReadPhase m () -> m ()
forall a b. (a -> b) -> a -> b
$ () -> ReadPhase m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE fireEvents #-}
newEventWithTriggerRef :: (MonadReflexCreateTrigger t m, MonadRef m, Ref m ~ Ref IO) => m (Event t a, Ref m (Maybe (EventTrigger t a)))
newEventWithTriggerRef :: m (Event t a, Ref m (Maybe (EventTrigger t a)))
newEventWithTriggerRef = do
IORef (Maybe (EventTrigger t a))
rt <- Maybe (EventTrigger t a) -> m (Ref m (Maybe (EventTrigger t a)))
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef Maybe (EventTrigger t a)
forall a. Maybe a
Nothing
Event t a
e <- (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
MonadReflexCreateTrigger t m =>
(EventTrigger t a -> IO (IO ())) -> m (Event t a)
newEventWithTrigger ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall a b. (a -> b) -> a -> b
$ \t :: EventTrigger t a
t -> do
Ref IO (Maybe (EventTrigger t a))
-> Maybe (EventTrigger t a) -> IO ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef IORef (Maybe (EventTrigger t a))
Ref IO (Maybe (EventTrigger t a))
rt (Maybe (EventTrigger t a) -> IO ())
-> Maybe (EventTrigger t a) -> IO ()
forall a b. (a -> b) -> a -> b
$ EventTrigger t a -> Maybe (EventTrigger t a)
forall a. a -> Maybe a
Just EventTrigger t a
t
IO () -> IO (IO ())
forall (m :: * -> *) a. Monad m => a -> m a
return (IO () -> IO (IO ())) -> IO () -> IO (IO ())
forall a b. (a -> b) -> a -> b
$ Ref IO (Maybe (EventTrigger t a))
-> Maybe (EventTrigger t a) -> IO ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef IORef (Maybe (EventTrigger t a))
Ref IO (Maybe (EventTrigger t a))
rt Maybe (EventTrigger t a)
forall a. Maybe a
Nothing
(Event t a, IORef (Maybe (EventTrigger t a)))
-> m (Event t a, IORef (Maybe (EventTrigger t a)))
forall (m :: * -> *) a. Monad m => a -> m a
return (Event t a
e, IORef (Maybe (EventTrigger t a))
rt)
{-# INLINE newEventWithTriggerRef #-}
fireEventRef :: (MonadReflexHost t m, MonadRef m, Ref m ~ Ref IO) => Ref m (Maybe (EventTrigger t a)) -> a -> m ()
fireEventRef :: Ref m (Maybe (EventTrigger t a)) -> a -> m ()
fireEventRef mtRef :: Ref m (Maybe (EventTrigger t a))
mtRef input :: a
input = do
Maybe (EventTrigger t a)
mt <- Ref m (Maybe (EventTrigger t a)) -> m (Maybe (EventTrigger t a))
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m (Maybe (EventTrigger t a))
mtRef
case Maybe (EventTrigger t a)
mt of
Nothing -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just trigger :: EventTrigger t a
trigger -> [DSum (EventTrigger t) Identity] -> m ()
forall t (m :: * -> *).
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> m ()
fireEvents [EventTrigger t a
trigger EventTrigger t a -> Identity a -> DSum (EventTrigger t) Identity
forall k (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> a -> Identity a
forall a. a -> Identity a
Identity a
input]
fireEventRefAndRead :: (MonadReflexHost t m, MonadRef m, Ref m ~ Ref IO) => Ref m (Maybe (EventTrigger t a)) -> a -> EventHandle t b -> m (Maybe b)
fireEventRefAndRead :: Ref m (Maybe (EventTrigger t a))
-> a -> EventHandle t b -> m (Maybe b)
fireEventRefAndRead mtRef :: Ref m (Maybe (EventTrigger t a))
mtRef input :: a
input e :: EventHandle t b
e = do
Maybe (EventTrigger t a)
mt <- Ref m (Maybe (EventTrigger t a)) -> m (Maybe (EventTrigger t a))
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m (Maybe (EventTrigger t a))
mtRef
case Maybe (EventTrigger t a)
mt of
Nothing -> Maybe b -> m (Maybe b)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe b
forall a. Maybe a
Nothing
Just trigger :: EventTrigger t a
trigger -> [DSum (EventTrigger t) Identity]
-> ReadPhase m (Maybe b) -> m (Maybe b)
forall t (m :: * -> *) a.
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
fireEventsAndRead [EventTrigger t a
trigger EventTrigger t a -> Identity a -> DSum (EventTrigger t) Identity
forall k (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> a -> Identity a
forall a. a -> Identity a
Identity a
input] (ReadPhase m (Maybe b) -> m (Maybe b))
-> ReadPhase m (Maybe b) -> m (Maybe b)
forall a b. (a -> b) -> a -> b
$ do
Maybe (ReadPhase m b)
mGetValue <- EventHandle t b -> ReadPhase m (Maybe (ReadPhase m b))
forall t (m :: * -> *) a.
MonadReadEvent t m =>
EventHandle t a -> m (Maybe (m a))
readEvent EventHandle t b
e
case Maybe (ReadPhase m b)
mGetValue of
Nothing -> Maybe b -> ReadPhase m (Maybe b)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe b
forall a. Maybe a
Nothing
Just getValue :: ReadPhase m b
getValue -> (b -> Maybe b) -> ReadPhase m b -> ReadPhase m (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Maybe b
forall a. a -> Maybe a
Just ReadPhase m b
getValue
instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (ReaderT r m) where
newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> ReaderT r m (Event t a)
newEventWithTrigger = m (Event t a) -> ReaderT r m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> ReaderT r m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> ReaderT r m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
MonadReflexCreateTrigger t m =>
(EventTrigger t a -> IO (IO ())) -> m (Event t a)
newEventWithTrigger
newFanEventWithTrigger :: (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> ReaderT r m (EventSelector t k)
newFanEventWithTrigger initializer :: forall a. k a -> EventTrigger t a -> IO (IO ())
initializer = m (EventSelector t k) -> ReaderT r m (EventSelector t k)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k) -> ReaderT r m (EventSelector t k))
-> m (EventSelector t k) -> ReaderT r m (EventSelector t k)
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
forall t (m :: * -> *) (k :: * -> *).
(MonadReflexCreateTrigger t m, GCompare k) =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
initializer
instance MonadSubscribeEvent t m => MonadSubscribeEvent t (ReaderT r m) where
subscribeEvent :: Event t a -> ReaderT r m (EventHandle t a)
subscribeEvent = m (EventHandle t a) -> ReaderT r m (EventHandle t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventHandle t a) -> ReaderT r m (EventHandle t a))
-> (Event t a -> m (EventHandle t a))
-> Event t a
-> ReaderT r m (EventHandle t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (EventHandle t a)
forall t (m :: * -> *) a.
MonadSubscribeEvent t m =>
Event t a -> m (EventHandle t a)
subscribeEvent
instance MonadReflexHost t m => MonadReflexHost t (ReaderT r m) where
type ReadPhase (ReaderT r m) = ReadPhase m
fireEventsAndRead :: [DSum (EventTrigger t) Identity]
-> ReadPhase (ReaderT r m) a -> ReaderT r m a
fireEventsAndRead dm :: [DSum (EventTrigger t) Identity]
dm a :: ReadPhase (ReaderT r m) a
a = m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a) -> m a -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ [DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
fireEventsAndRead [DSum (EventTrigger t) Identity]
dm ReadPhase m a
ReadPhase (ReaderT r m) a
a
runHostFrame :: HostFrame t a -> ReaderT r m a
runHostFrame = m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> (HostFrame t a -> m a) -> HostFrame t a -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostFrame t a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
HostFrame t a -> m a
runHostFrame
instance (MonadReflexCreateTrigger t m, Monoid w) => MonadReflexCreateTrigger t (WriterT w m) where
newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> WriterT w m (Event t a)
newEventWithTrigger = m (Event t a) -> WriterT w m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> WriterT w m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> WriterT w m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
MonadReflexCreateTrigger t m =>
(EventTrigger t a -> IO (IO ())) -> m (Event t a)
newEventWithTrigger
newFanEventWithTrigger :: (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> WriterT w m (EventSelector t k)
newFanEventWithTrigger initializer :: forall a. k a -> EventTrigger t a -> IO (IO ())
initializer = m (EventSelector t k) -> WriterT w m (EventSelector t k)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k) -> WriterT w m (EventSelector t k))
-> m (EventSelector t k) -> WriterT w m (EventSelector t k)
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
forall t (m :: * -> *) (k :: * -> *).
(MonadReflexCreateTrigger t m, GCompare k) =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
initializer
instance (MonadSubscribeEvent t m, Monoid w) => MonadSubscribeEvent t (WriterT w m) where
subscribeEvent :: Event t a -> WriterT w m (EventHandle t a)
subscribeEvent = m (EventHandle t a) -> WriterT w m (EventHandle t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventHandle t a) -> WriterT w m (EventHandle t a))
-> (Event t a -> m (EventHandle t a))
-> Event t a
-> WriterT w m (EventHandle t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (EventHandle t a)
forall t (m :: * -> *) a.
MonadSubscribeEvent t m =>
Event t a -> m (EventHandle t a)
subscribeEvent
instance (MonadReflexHost t m, Monoid w) => MonadReflexHost t (WriterT w m) where
type ReadPhase (WriterT w m) = ReadPhase m
fireEventsAndRead :: [DSum (EventTrigger t) Identity]
-> ReadPhase (WriterT w m) a -> WriterT w m a
fireEventsAndRead dm :: [DSum (EventTrigger t) Identity]
dm a :: ReadPhase (WriterT w m) a
a = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a) -> m a -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ [DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
fireEventsAndRead [DSum (EventTrigger t) Identity]
dm ReadPhase m a
ReadPhase (WriterT w m) a
a
runHostFrame :: HostFrame t a -> WriterT w m a
runHostFrame = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> (HostFrame t a -> m a) -> HostFrame t a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostFrame t a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
HostFrame t a -> m a
runHostFrame
instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (StateT s m) where
newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> StateT s m (Event t a)
newEventWithTrigger = m (Event t a) -> StateT s m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> StateT s m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> StateT s m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
MonadReflexCreateTrigger t m =>
(EventTrigger t a -> IO (IO ())) -> m (Event t a)
newEventWithTrigger
newFanEventWithTrigger :: (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> StateT s m (EventSelector t k)
newFanEventWithTrigger initializer :: forall a. k a -> EventTrigger t a -> IO (IO ())
initializer = m (EventSelector t k) -> StateT s m (EventSelector t k)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k) -> StateT s m (EventSelector t k))
-> m (EventSelector t k) -> StateT s m (EventSelector t k)
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
forall t (m :: * -> *) (k :: * -> *).
(MonadReflexCreateTrigger t m, GCompare k) =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
initializer
instance MonadSubscribeEvent t m => MonadSubscribeEvent t (StateT r m) where
subscribeEvent :: Event t a -> StateT r m (EventHandle t a)
subscribeEvent = m (EventHandle t a) -> StateT r m (EventHandle t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventHandle t a) -> StateT r m (EventHandle t a))
-> (Event t a -> m (EventHandle t a))
-> Event t a
-> StateT r m (EventHandle t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (EventHandle t a)
forall t (m :: * -> *) a.
MonadSubscribeEvent t m =>
Event t a -> m (EventHandle t a)
subscribeEvent
instance MonadReflexHost t m => MonadReflexHost t (StateT s m) where
type ReadPhase (StateT s m) = ReadPhase m
fireEventsAndRead :: [DSum (EventTrigger t) Identity]
-> ReadPhase (StateT s m) a -> StateT s m a
fireEventsAndRead dm :: [DSum (EventTrigger t) Identity]
dm a :: ReadPhase (StateT s m) a
a = m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT s m a) -> m a -> StateT s m a
forall a b. (a -> b) -> a -> b
$ [DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
fireEventsAndRead [DSum (EventTrigger t) Identity]
dm ReadPhase m a
ReadPhase (StateT s m) a
a
runHostFrame :: HostFrame t a -> StateT s m a
runHostFrame = m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT s m a)
-> (HostFrame t a -> m a) -> HostFrame t a -> StateT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostFrame t a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
HostFrame t a -> m a
runHostFrame
instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (Strict.StateT s m) where
newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> StateT s m (Event t a)
newEventWithTrigger = m (Event t a) -> StateT s m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> StateT s m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> StateT s m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
MonadReflexCreateTrigger t m =>
(EventTrigger t a -> IO (IO ())) -> m (Event t a)
newEventWithTrigger
newFanEventWithTrigger :: (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> StateT s m (EventSelector t k)
newFanEventWithTrigger initializer :: forall a. k a -> EventTrigger t a -> IO (IO ())
initializer = m (EventSelector t k) -> StateT s m (EventSelector t k)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k) -> StateT s m (EventSelector t k))
-> m (EventSelector t k) -> StateT s m (EventSelector t k)
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
forall t (m :: * -> *) (k :: * -> *).
(MonadReflexCreateTrigger t m, GCompare k) =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
initializer
instance MonadSubscribeEvent t m => MonadSubscribeEvent t (Strict.StateT r m) where
subscribeEvent :: Event t a -> StateT r m (EventHandle t a)
subscribeEvent = m (EventHandle t a) -> StateT r m (EventHandle t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventHandle t a) -> StateT r m (EventHandle t a))
-> (Event t a -> m (EventHandle t a))
-> Event t a
-> StateT r m (EventHandle t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (EventHandle t a)
forall t (m :: * -> *) a.
MonadSubscribeEvent t m =>
Event t a -> m (EventHandle t a)
subscribeEvent
instance MonadReflexHost t m => MonadReflexHost t (Strict.StateT s m) where
type ReadPhase (Strict.StateT s m) = ReadPhase m
fireEventsAndRead :: [DSum (EventTrigger t) Identity]
-> ReadPhase (StateT s m) a -> StateT s m a
fireEventsAndRead dm :: [DSum (EventTrigger t) Identity]
dm a :: ReadPhase (StateT s m) a
a = m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT s m a) -> m a -> StateT s m a
forall a b. (a -> b) -> a -> b
$ [DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
fireEventsAndRead [DSum (EventTrigger t) Identity]
dm ReadPhase m a
ReadPhase (StateT s m) a
a
runHostFrame :: HostFrame t a -> StateT s m a
runHostFrame = m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT s m a)
-> (HostFrame t a -> m a) -> HostFrame t a -> StateT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostFrame t a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
HostFrame t a -> m a
runHostFrame
instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (ContT r m) where
newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> ContT r m (Event t a)
newEventWithTrigger = m (Event t a) -> ContT r m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> ContT r m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> ContT r m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
MonadReflexCreateTrigger t m =>
(EventTrigger t a -> IO (IO ())) -> m (Event t a)
newEventWithTrigger
newFanEventWithTrigger :: (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> ContT r m (EventSelector t k)
newFanEventWithTrigger initializer :: forall a. k a -> EventTrigger t a -> IO (IO ())
initializer = m (EventSelector t k) -> ContT r m (EventSelector t k)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k) -> ContT r m (EventSelector t k))
-> m (EventSelector t k) -> ContT r m (EventSelector t k)
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
forall t (m :: * -> *) (k :: * -> *).
(MonadReflexCreateTrigger t m, GCompare k) =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
initializer
instance MonadSubscribeEvent t m => MonadSubscribeEvent t (ContT r m) where
subscribeEvent :: Event t a -> ContT r m (EventHandle t a)
subscribeEvent = m (EventHandle t a) -> ContT r m (EventHandle t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventHandle t a) -> ContT r m (EventHandle t a))
-> (Event t a -> m (EventHandle t a))
-> Event t a
-> ContT r m (EventHandle t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (EventHandle t a)
forall t (m :: * -> *) a.
MonadSubscribeEvent t m =>
Event t a -> m (EventHandle t a)
subscribeEvent
instance MonadReflexHost t m => MonadReflexHost t (ContT r m) where
type ReadPhase (ContT r m) = ReadPhase m
fireEventsAndRead :: [DSum (EventTrigger t) Identity]
-> ReadPhase (ContT r m) a -> ContT r m a
fireEventsAndRead dm :: [DSum (EventTrigger t) Identity]
dm a :: ReadPhase (ContT r m) a
a = m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ContT r m a) -> m a -> ContT r m a
forall a b. (a -> b) -> a -> b
$ [DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
fireEventsAndRead [DSum (EventTrigger t) Identity]
dm ReadPhase m a
ReadPhase (ContT r m) a
a
runHostFrame :: HostFrame t a -> ContT r m a
runHostFrame = m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ContT r m a)
-> (HostFrame t a -> m a) -> HostFrame t a -> ContT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostFrame t a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
HostFrame t a -> m a
runHostFrame
instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (ExceptT e m) where
newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> ExceptT e m (Event t a)
newEventWithTrigger = m (Event t a) -> ExceptT e m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> ExceptT e m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> ExceptT e m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
MonadReflexCreateTrigger t m =>
(EventTrigger t a -> IO (IO ())) -> m (Event t a)
newEventWithTrigger
newFanEventWithTrigger :: (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> ExceptT e m (EventSelector t k)
newFanEventWithTrigger initializer :: forall a. k a -> EventTrigger t a -> IO (IO ())
initializer = m (EventSelector t k) -> ExceptT e m (EventSelector t k)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k) -> ExceptT e m (EventSelector t k))
-> m (EventSelector t k) -> ExceptT e m (EventSelector t k)
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
forall t (m :: * -> *) (k :: * -> *).
(MonadReflexCreateTrigger t m, GCompare k) =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
initializer
instance MonadSubscribeEvent t m => MonadSubscribeEvent t (ExceptT r m) where
subscribeEvent :: Event t a -> ExceptT r m (EventHandle t a)
subscribeEvent = m (EventHandle t a) -> ExceptT r m (EventHandle t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventHandle t a) -> ExceptT r m (EventHandle t a))
-> (Event t a -> m (EventHandle t a))
-> Event t a
-> ExceptT r m (EventHandle t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (EventHandle t a)
forall t (m :: * -> *) a.
MonadSubscribeEvent t m =>
Event t a -> m (EventHandle t a)
subscribeEvent
instance MonadReflexHost t m => MonadReflexHost t (ExceptT e m) where
type ReadPhase (ExceptT e m) = ReadPhase m
fireEventsAndRead :: [DSum (EventTrigger t) Identity]
-> ReadPhase (ExceptT e m) a -> ExceptT e m a
fireEventsAndRead dm :: [DSum (EventTrigger t) Identity]
dm a :: ReadPhase (ExceptT e m) a
a = m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ExceptT e m a) -> m a -> ExceptT e m a
forall a b. (a -> b) -> a -> b
$ [DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
fireEventsAndRead [DSum (EventTrigger t) Identity]
dm ReadPhase m a
ReadPhase (ExceptT e m) a
a
runHostFrame :: HostFrame t a -> ExceptT e m a
runHostFrame = m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ExceptT e m a)
-> (HostFrame t a -> m a) -> HostFrame t a -> ExceptT e m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostFrame t a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
HostFrame t a -> m a
runHostFrame
instance (MonadReflexCreateTrigger t m, Monoid w) => MonadReflexCreateTrigger t (RWST r w s m) where
newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> RWST r w s m (Event t a)
newEventWithTrigger = m (Event t a) -> RWST r w s m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> RWST r w s m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> RWST r w s m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
MonadReflexCreateTrigger t m =>
(EventTrigger t a -> IO (IO ())) -> m (Event t a)
newEventWithTrigger
newFanEventWithTrigger :: (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> RWST r w s m (EventSelector t k)
newFanEventWithTrigger initializer :: forall a. k a -> EventTrigger t a -> IO (IO ())
initializer = m (EventSelector t k) -> RWST r w s m (EventSelector t k)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k) -> RWST r w s m (EventSelector t k))
-> m (EventSelector t k) -> RWST r w s m (EventSelector t k)
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
forall t (m :: * -> *) (k :: * -> *).
(MonadReflexCreateTrigger t m, GCompare k) =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
initializer
instance (MonadSubscribeEvent t m, Monoid w) => MonadSubscribeEvent t (RWST r w s m) where
subscribeEvent :: Event t a -> RWST r w s m (EventHandle t a)
subscribeEvent = m (EventHandle t a) -> RWST r w s m (EventHandle t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventHandle t a) -> RWST r w s m (EventHandle t a))
-> (Event t a -> m (EventHandle t a))
-> Event t a
-> RWST r w s m (EventHandle t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (EventHandle t a)
forall t (m :: * -> *) a.
MonadSubscribeEvent t m =>
Event t a -> m (EventHandle t a)
subscribeEvent
instance (MonadReflexHost t m, Monoid w) => MonadReflexHost t (RWST r w s m) where
type ReadPhase (RWST r w s m) = ReadPhase m
fireEventsAndRead :: [DSum (EventTrigger t) Identity]
-> ReadPhase (RWST r w s m) a -> RWST r w s m a
fireEventsAndRead dm :: [DSum (EventTrigger t) Identity]
dm a :: ReadPhase (RWST r w s m) a
a = m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w s m a) -> m a -> RWST r w s m a
forall a b. (a -> b) -> a -> b
$ [DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
[DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a
fireEventsAndRead [DSum (EventTrigger t) Identity]
dm ReadPhase m a
ReadPhase (RWST r w s m) a
a
runHostFrame :: HostFrame t a -> RWST r w s m a
runHostFrame = m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w s m a)
-> (HostFrame t a -> m a) -> HostFrame t a -> RWST r w s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostFrame t a -> m a
forall t (m :: * -> *) a.
MonadReflexHost t m =>
HostFrame t a -> m a
runHostFrame