Halogen.Subscription
- Package
- purescript-halogen-subscriptions
- Repository
- purescript-halogen/purescript-halogen-subscriptions
#SubscribeIO Source
type SubscribeIO a = { emitter :: Emitter a, listener :: Listener a }A paired Listener and Emitter produced with the create function.
#create Source
create :: forall a. Effect (SubscribeIO a)Create a paired Listener and Emitter, where you can push values to
the listener and subscribe to values from the emitter.
{ emitter, listener } <- create
-- Push values into the listener:
notify listener "hello"
-- Subscribe to outputs from the emitter with a callback:
subscription <- subscribe emitter \value ->
Console.log value
-- Unsubscribe at any time:
unsubscribe subscription
#Listener Source
newtype Listener aConceptually, a Listener represents an input source to an Emitter. You
can push a value to its paired emitter with the notify function.
Instances
#Emitter Source
newtype Emitter aAn Emitter represents a collection of discrete occurrences of an event;
conceptually, an emitter is a possibly-infinite list of values.
Emitters are created from real events like timers or mouse clicks and can be combined or transformed with the functions and instances in this module.
Emitters are consumed by providing a callback via the subscribe function.
Instances
#Subscription Source
newtype SubscriptionA Subscription results from subscribing to an Emitter with subscribe;
the subscription can be ended at any time with unsubscribe.
Instances
#subscribe Source
subscribe :: forall r a. Emitter a -> (a -> Effect r) -> Effect SubscriptionSubscribe to an Emitter by providing a callback to run on values produced
by the emitter:
-- Produce an emitter / listener pair with `create`:
{ emitter, listener } <- create
-- Then, subscribe to the emitter by providing a callback:
subscription <- subscribe emitter \emitted ->
doSomethingWith emitted
-- End the subscription at any time with `unsubscribe`:
unsubscribe subscription
#unsubscribe Source
unsubscribe :: Subscription -> Effect UnitEnd a subscription to an Emitter.
- Modules
- Halogen.
Subscription