Skip to content

Files

Latest commit

 

History

History
101 lines (68 loc) · 2.63 KB

SubscribeF.md

File metadata and controls

101 lines (68 loc) · 2.63 KB

Module Halogen.Query.SubscribeF

A part of the HalogenF algebra that allows subscription to event listeners.

EventSource

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

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_

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)

SubscribeF

data SubscribeF f g a
  = Subscribe (EventSource f g) a

The subscribe algebra.

Instances
instance functorSubscribeF :: Functor (SubscribeF f g)

remapSubscribe

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

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

transformSubscribe :: forall f f' g g'. (Functor g, Functor g') => Natural f f' -> Natural g g' -> Natural (SubscribeF f g) (SubscribeF f' g')

subscribeN

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.