A part of the HalogenF
algebra that allows subscription to event
listeners.
type EventSource f g = StallingProducer (f Unit) g Unit
A type alias for a coroutine producer used to represent a subscribable source of events.
eventSource :: forall eff a f. ((a -> Eff (avar :: AVAR | eff) Unit) -> Eff (avar :: AVAR | eff) Unit) -> (a -> Eff (avar :: AVAR | eff) (f Unit)) -> EventSource f (Aff (avar :: AVAR | eff))
Creates an EventSource
for an event listener that accepts one argument.
- The first argument is the function that attaches the event listener.
- The second argument is a handler that produces a value in
f
.
For example:
let onCopied = eventSource (Editor.onCopy editor) \text -> do
pure $ actionF (TextCopied text)
(Taken from the Ace component example)
eventSource_ :: forall eff f. (Eff (avar :: AVAR | eff) Unit -> Eff (avar :: AVAR | eff) Unit) -> Eff (avar :: AVAR | eff) (f Unit) -> EventSource f (Aff (avar :: AVAR | eff))
Creates an EventSource
for an event listener that accepts no arguments.
- The first argument is the function that attaches the event listener.
- The second argument is a handler that produces a value in
f
.
For example:
let onChange = eventSource_ (Session.onChange session) do
text <- Editor.getValue editor
pure $ actionF (ChangeText text)
(Taken from the Ace component example)
data SubscribeF f g a
= Subscribe (EventSource f g) a
The subscribe algebra.
instance functorSubscribeF :: Functor (SubscribeF f g)
remapSubscribe :: forall f g h. (Functor h) => Natural f g -> Natural (SubscribeF f h) (SubscribeF g h)
Changes the generating functor for an EventSource
. Used internally by
Halogen.
hoistSubscribe :: forall f g h. (Functor h) => Natural g h -> Natural (SubscribeF f g) (SubscribeF f h)
Changes the underlying monad for an EventSource
. Used internally by
Halogen.
transformSubscribe :: forall f f' g g'. (Functor g, Functor g') => Natural f f' -> Natural g g' -> Natural (SubscribeF f g) (SubscribeF f' g')
subscribeN :: forall f g. (MonadRec g) => Consumer (f Unit) g Unit -> Natural (SubscribeF f g) g
A natural transformation for interpreting the subscribe algebra as its underlying monad, via a coroutine consumer. Used internally by Halogen.