reflex-0.9.0.0: Higher-order Functional Reactive Programming
Safe HaskellSafe-Inferred
LanguageHaskell2010

Reflex.Host.Class

Description

This module provides the interface for hosting Reflex engines. This should only be necessary if you're writing a binding or some other library that provides a core event loop.

Synopsis

Documentation

class (Reflex t, MonadReflexCreateTrigger t (HostFrame t), MonadSample t (HostFrame t), MonadHold t (HostFrame t), MonadFix (HostFrame t), MonadSubscribeEvent t (HostFrame t)) => ReflexHost t Source #

Framework implementation support class for the reflex implementation represented by t.

Associated Types

type EventTrigger t :: Type -> Type Source #

type EventHandle t :: Type -> Type Source #

type HostFrame t :: Type -> Type Source #

Instances

Instances details
ReflexHost t => ReflexHost (ProfiledTimeline t) Source # 
Instance details

Defined in Reflex.Profiled

HasSpiderTimeline x => ReflexHost (SpiderTimeline x) Source # 
Instance details

Defined in Reflex.Spider.Internal

class (Reflex t, Monad m) => MonadSubscribeEvent t m | m -> t where Source #

Monad in which Events can be subscribed. This forces all underlying event sources to be initialized, so that the event will fire whenever it ought to. Events must be subscribed before they are read using readEvent

Methods

subscribeEvent :: Event t a -> m (EventHandle t a) Source #

Subscribe to an event and set it up if needed.

This function will create a new EventHandle from an Event. This handle may then be used via readEvent in the read callback of fireEventsAndRead.

If the event wasn't subscribed to before (either manually or through a dependent event or behavior) then this function will cause the event and all dependencies of this event to be set up. For example, if the event was created by newEventWithTrigger, then it's callback will be executed.

It's safe to call this function multiple times.

Instances

Instances details
MonadSubscribeEvent t m => MonadSubscribeEvent t (ExceptT r m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

subscribeEvent :: Event t a -> ExceptT r m (EventHandle t a) Source #

MonadSubscribeEvent t m => MonadSubscribeEvent t (ReaderT r m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

subscribeEvent :: Event t a -> ReaderT r m (EventHandle t a) Source #

MonadSubscribeEvent t m => MonadSubscribeEvent t (StateT r m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

subscribeEvent :: Event t a -> StateT r m (EventHandle t a) Source #

MonadSubscribeEvent t m => MonadSubscribeEvent t (StateT r m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

subscribeEvent :: Event t a -> StateT r m (EventHandle t a) Source #

(MonadSubscribeEvent t m, Monoid w) => MonadSubscribeEvent t (WriterT w m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

subscribeEvent :: Event t a -> WriterT w m (EventHandle t a) Source #

MonadSubscribeEvent t m => MonadSubscribeEvent t (ContT r m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

subscribeEvent :: Event t a -> ContT r m (EventHandle t a) Source #

(MonadSubscribeEvent t m, Monoid w) => MonadSubscribeEvent t (RWST r w s m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

subscribeEvent :: Event t a -> RWST r w s m (EventHandle t a) Source #

HasSpiderTimeline x => MonadSubscribeEvent (SpiderTimeline x) (SpiderHost x) Source # 
Instance details

Defined in Reflex.Spider.Internal

HasSpiderTimeline x => MonadSubscribeEvent (SpiderTimeline x) (SpiderHostFrame x) Source # 
Instance details

Defined in Reflex.Spider.Internal

MonadSubscribeEvent t m => MonadSubscribeEvent (ProfiledTimeline t) (ProfiledM m) Source # 
Instance details

Defined in Reflex.Profiled

class (ReflexHost t, Applicative m, Monad m) => MonadReadEvent t m | m -> t where Source #

Monad that allows to read events' values.

Methods

readEvent :: EventHandle t a -> m (Maybe (m a)) Source #

Read the value of an Event from an EventHandle (created by calling subscribeEvent).

After event propagation is done, all events can be in two states: either they are firing with some value or they are not firing. In the former case, this function returns Just act, where act in an action to read the current value of the event. In the latter case, the function returns Nothing.

This function is normally used in the calllback for fireEventsAndRead.

Instances

Instances details
MonadReadEvent t m => MonadReadEvent (ProfiledTimeline t) (ProfiledM m) Source # 
Instance details

Defined in Reflex.Profiled

HasSpiderTimeline x => MonadReadEvent (SpiderTimeline x) (ReadPhase x) Source # 
Instance details

Defined in Reflex.Spider.Internal

class (Applicative m, Monad m) => MonadReflexCreateTrigger t m | m -> t where Source #

A monad where new events feed from external sources can be created.

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> m (Event t a) Source #

Creates a root Event (one that is not based on any other event).

When a subscriber first subscribes to an event (building another event that depends on the subscription) the given callback function is run and passed a trigger. The callback function can then set up the event source in IO. After this is done, the callback function must return an accompanying teardown action.

Any time between setup and teardown the trigger can be used to fire the event, by passing it to fireEventsAndRead.

Note: An event may be set up multiple times. So after the teardown action is executed, the event may still be set up again in the future.

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> m (EventSelector t k) Source #

Instances

Instances details
(ReflexHost t, MonadReflexCreateTrigger t m) => MonadReflexCreateTrigger t (PostBuildT t m) Source # 
Instance details

Defined in Reflex.PostBuild.Base

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> PostBuildT t m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> PostBuildT t m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (TriggerEventT t m) Source # 
Instance details

Defined in Reflex.TriggerEvent.Base

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> TriggerEventT t m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> TriggerEventT t m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (ExceptT e m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> ExceptT e m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> ExceptT e m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (ReaderT r m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> ReaderT r m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> ReaderT r m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (StateT s m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> StateT s m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> StateT s m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (StateT s m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> StateT s m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> StateT s m (EventSelector t k) Source #

(MonadReflexCreateTrigger t m, Monoid w) => MonadReflexCreateTrigger t (WriterT w m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> WriterT w m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> WriterT w m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (BehaviorWriterT t w m) Source # 
Instance details

Defined in Reflex.BehaviorWriter.Base

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> BehaviorWriterT t w m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> BehaviorWriterT t w m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (DynamicWriterT t w m) Source # 
Instance details

Defined in Reflex.DynamicWriter.Base

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> DynamicWriterT t w m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> DynamicWriterT t w m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (EventWriterT t w m) Source # 
Instance details

Defined in Reflex.EventWriter.Base

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> EventWriterT t w m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> EventWriterT t w m (EventSelector t k) Source #

ReflexHost t => MonadReflexCreateTrigger t (PerformEventT t m) Source # 
Instance details

Defined in Reflex.PerformEvent.Base

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> PerformEventT t m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> PerformEventT t m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (QueryT t q m) Source # 
Instance details

Defined in Reflex.Query.Base

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> QueryT t q m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> QueryT t q m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (ContT r m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> ContT r m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> ContT r m (EventSelector t k) Source #

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (RequesterT t request response m) Source # 
Instance details

Defined in Reflex.Requester.Base.Internal

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> RequesterT t request response m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> RequesterT t request response m (EventSelector t k) Source #

(MonadReflexCreateTrigger t m, Monoid w) => MonadReflexCreateTrigger t (RWST r w s m) Source # 
Instance details

Defined in Reflex.Host.Class

Methods

newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> RWST r w s m (Event t a) Source #

newFanEventWithTrigger :: GCompare k => (forall a. k a -> EventTrigger t a -> IO (IO ())) -> RWST r w s m (EventSelector t k) Source #

HasSpiderTimeline x => MonadReflexCreateTrigger (SpiderTimeline x) (SpiderHost x) Source # 
Instance details

Defined in Reflex.Spider.Internal

HasSpiderTimeline x => MonadReflexCreateTrigger (SpiderTimeline x) (SpiderHostFrame x) Source # 
Instance details

Defined in Reflex.Spider.Internal

MonadReflexCreateTrigger t m => MonadReflexCreateTrigger (ProfiledTimeline t) (ProfiledM m) Source # 
Instance details

Defined in Reflex.Profiled

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 Source #

MonadReflexHost designates monads that can run reflex frames.

Associated Types

type ReadPhase m :: Type -> Type Source #

Methods

fireEventsAndRead :: [DSum (EventTrigger t) Identity] -> ReadPhase m a -> m a Source #

Propagate some events firings and read the values of events afterwards.

This function will create a new frame to fire the given events. It will then update all dependent events and behaviors. After that is done, the given callback is executed which allows to read the final values of events and check whether they have fired in this frame or not.

All events that are given are fired at the same time.

This function is typically used in the main loop of a reflex framework implementation. The main loop waits for external events to happen (such as keyboard input or a mouse click) and then fires the corresponding events using this function. The read callback can be used to read output events and perform a corresponding response action to the external event.

runHostFrame :: HostFrame t a -> m a Source #

Run a frame without any events firing.

This function should be used when you want to use sample and hold when no events are currently firing. Using this function in that case can improve performance, since the implementation can assume that no events are firing when sample or hold are called.

This function is commonly used to set up the basic event network when the application starts up.

Instances

Instances details
MonadReflexHost t m => MonadReflexHost t (ExceptT e m) Source # 
Instance details

Defined in Reflex.Host.Class

Associated Types

type ReadPhase (ExceptT e m) :: Type -> Type Source #

MonadReflexHost t m => MonadReflexHost t (ReaderT r m) Source # 
Instance details

Defined in Reflex.Host.Class

Associated Types

type ReadPhase (ReaderT r m) :: Type -> Type Source #

MonadReflexHost t m => MonadReflexHost t (StateT s m) Source # 
Instance details

Defined in Reflex.Host.Class

Associated Types

type ReadPhase (StateT s m) :: Type -> Type Source #

MonadReflexHost t m => MonadReflexHost t (StateT s m) Source # 
Instance details

Defined in Reflex.Host.Class

Associated Types

type ReadPhase (StateT s m) :: Type -> Type Source #

(MonadReflexHost t m, Monoid w) => MonadReflexHost t (WriterT w m) Source # 
Instance details

Defined in Reflex.Host.Class

Associated Types

type ReadPhase (WriterT w m) :: Type -> Type Source #

MonadReflexHost t m => MonadReflexHost t (ContT r m) Source # 
Instance details

Defined in Reflex.Host.Class

Associated Types

type ReadPhase (ContT r m) :: Type -> Type Source #

(MonadReflexHost t m, Monoid w) => MonadReflexHost t (RWST r w s m) Source # 
Instance details

Defined in Reflex.Host.Class

Associated Types

type ReadPhase (RWST r w s m) :: Type -> Type Source #

Methods

fireEventsAndRead :: [DSum (EventTrigger t) Identity] -> ReadPhase (RWST r w s m) a -> RWST r w s m a Source #

runHostFrame :: HostFrame t a -> RWST r w s m a Source #

HasSpiderTimeline x => MonadReflexHost (SpiderTimeline x) (SpiderHost x) Source # 
Instance details

Defined in Reflex.Spider.Internal

Associated Types

type ReadPhase (SpiderHost x) :: Type -> Type Source #

MonadReflexHost t m => MonadReflexHost (ProfiledTimeline t) (ProfiledM m) Source # 
Instance details

Defined in Reflex.Profiled

Associated Types

type ReadPhase (ProfiledM m) :: Type -> Type Source #

fireEvents :: MonadReflexHost t m => [DSum (EventTrigger t) Identity] -> m () Source #

Like fireEventsAndRead, but without reading any events.

newEventWithTriggerRef :: (MonadReflexCreateTrigger t m, MonadRef m, Ref m ~ Ref IO) => m (Event t a, Ref m (Maybe (EventTrigger t a))) Source #

Create a new event and store its trigger in an IORef while it's active.

An event is only active between the set up (when it's first subscribed to) and the teardown phases (when noboby is subscribing the event anymore). This function returns an Event and an IORef. As long as the event is active, the IORef will contain Just the event trigger to trigger this event. When the event is not active, the IORef will contain Nothing. This allows event sources to be more efficient, since they don't need to produce events when nobody is listening.

fireEventRef :: (MonadReflexHost t m, MonadRef m, Ref m ~ Ref IO) => Ref m (Maybe (EventTrigger t a)) -> a -> m () Source #

Fire the given trigger if it is not Nothing.

fireEventRefAndRead :: (MonadReflexHost t m, MonadRef m, Ref m ~ Ref IO) => Ref m (Maybe (EventTrigger t a)) -> a -> EventHandle t b -> m (Maybe b) Source #

Fire the given trigger if it is not Nothing, and read from the given EventHandle.