Halogen.Query.EventSource
- Package
- purescript-halogen
- Repository
- purescript-halogen/purescript-halogen
#EventSource Source
newtype EventSource m a
An event source definition - an effect in m
that when run returns a
producer coroutine that emits actions of type a
, and runs in the effect
monad m
.
It's generally unnecessary to build values of this type directly, the
affEventSource
, effectEventSource
, and eventListenerEventSource
cover most common event source constructions.
Constructors
EventSource (m { finalizer :: Finalizer m, producer :: Producer a m Unit })
Instances
Newtype (EventSource m a) _
(Functor m) => Functor (EventSource m)
#hoist Source
hoist :: forall n m. Functor n => (m ~> n) -> (EventSource m) ~> (EventSource n)
Changes the effect monad of an event source.
#affEventSource Source
affEventSource :: forall a m. MonadAff m => (Emitter Aff a -> Aff (Finalizer Aff)) -> EventSource m a
Constructs an event source from a setup function that operates in Aff
.
- The
Emitter
that the passed function receives is used toemit
actions that will be received by the current component, or can beclose
d to shut down the event source and remove the subscription. - The
Finalizer
that the passed function produces is there to allow for some clean-up action to be taken when the event source is unsubscribed from. This also runs if theEmitter
isclose
d.mempty
can be used here if there is no clean-up to perform.
#effectEventSource Source
effectEventSource :: forall a m. MonadAff m => (Emitter Effect a -> Effect (Finalizer Effect)) -> EventSource m a
Constructs an event source from a setup function that operates in Eff
.
- The
Emitter
that the passed function receives is used toemit
actions that will be received by the current component, or can beclose
d to shut down the event source and remove the subscription. - The
Finalizer
that the passed function produces is there to allow for some clean-up action to be taken when the event source is unsubscribed from. This also runs if theEmitter
isclose
d.mempty
can be used here if there is no clean-up to perform.
#eventListenerEventSource Source
eventListenerEventSource :: forall a m. MonadAff m => EventType -> EventTarget -> (Event -> Maybe a) -> EventSource m a
Constructs an event source from an event in the DOM. Accepts a function
that maps event values to a Maybe
-wrapped action, allowing it to filter
events if necessary.
#Emitter Source
newtype Emitter m a
Values of this type are created internally by affEventSource
and
effectEventSource
, and then passed into the user-provided setup function.
This type is just a wrapper around a callback, used to simplify the type signatures for setting up event sources.
Constructors
#close Source
close :: forall a m. Emitter m a -> m Unit
Closes the emitter, shutting down the event source. This allows an event source to stop itself internally, rather than requiring external shutdown by unsubscribing from it.
The event source will automatically be unsubscribed from when this is called, and the finalizer returned during event source setup will be executed.
Any further calls to emit
after close
will be ignored.
#Finalizer Source
newtype Finalizer m
When setting up an event source, values of this type should be returned to describe any clean-up operations required. This is just a newtype around an effectful operation, but helps with type signature comprehension.
There is a Monoid
instance provided for finalizers, so mempty
can be
used in cases where there are no relevant clean-up actions to take.
Constructors
Instances
- Modules
- Halogen
- Halogen.
Aff - Halogen.
Aff. Driver - Halogen.
Aff. Driver. Eval - Halogen.
Aff. Driver. State - Halogen.
Aff. Util - Halogen.
Component - Halogen.
Component. Profunctor - Halogen.
Data. OrdBox - Halogen.
Data. Slot - Halogen.
HTML - Halogen.
HTML. Core - Halogen.
HTML. Elements - Halogen.
HTML. Elements. Keyed - Halogen.
HTML. Events - Halogen.
HTML. Properties - Halogen.
HTML. Properties. ARIA - Halogen.
Query - Halogen.
Query. ChildQuery - Halogen.
Query. EventSource - Halogen.
Query. HalogenM - Halogen.
Query. HalogenQ - Halogen.
Query. Input - Halogen.
VDom. Driver