Halogen.Hooks.HookM
- Package
- purescript-halogen-hooks
- Repository
- thomashoneyman/purescript-halogen-hooks
A replacement for Halogen.Query.HalogenM
which supports a near-identical
API, but adjusted for compatibility with hooks. All functions available in
HalogenM
are still available here, but some have modified behavior (for
example, the state functions get
, put
, and modify
take a state
identifier as their first argument).
#HookF Source
data HookF :: (Type -> Type) -> Type -> Type
data HookF m a
A DSL compatible with HalogenM which is used to write effectful code for Hooks.
Constructors
Modify (StateId StateValue) (StateValue -> StateValue) (StateValue -> a)
Subscribe (SubscriptionId -> Emitter (HookM m Unit)) (SubscriptionId -> a)
Unsubscribe SubscriptionId a
Lift (m a)
ChildQuery (ChildQueryBox SlotType a)
Raise OutputValue a
Par (HookAp m a)
Fork (HookM m Unit) (ForkId -> a)
Kill ForkId a
GetRef RefLabel (Maybe Element -> a)
Instances
#HookM Source
newtype HookM :: (Type -> Type) -> Type -> Type
newtype HookM m a
The Hook effect monad, used to write effectful code in Hooks functions.
This monad is fully compatible with HalogenM
, meaning all functionality
available for HalogenM
is available in HookM
.
Constructors
Instances
Functor (HookM m)
Apply (HookM m)
Applicative (HookM m)
Bind (HookM m)
Monad (HookM m)
(Semigroup a) => Semigroup (HookM m a)
(Monoid a) => Monoid (HookM m a)
(MonadEffect m) => MonadEffect (HookM m)
(MonadAff m) => MonadAff (HookM m)
MonadTrans HookM
MonadRec (HookM m)
(MonadAsk r m) => MonadAsk r (HookM m)
(MonadTell w m) => MonadTell w (HookM m)
(MonadThrow e m) => MonadThrow e (HookM m)
Parallel (HookAp m) (HookM m)
#raise Source
raise :: forall o m. OutputToken o -> o -> HookM m Unit
Raise an output message for the component. Requires a token carrying the
output type of the component, which is provided by the Hooks.component
function.
#query Source
query :: forall m label ps query o' slot a _1. Cons label (Slot query o' slot) _1 ps => IsSymbol label => Ord slot => SlotToken ps -> Proxy label -> slot -> query a -> HookM m (Maybe a)
Send a query to a child of a component at the specified slot. Requires a
token carrying the slot type of the component, which is provided by the
Hooks.component
function.
#request Source
request :: forall m label ps query o' slot a _1. Cons label (Slot query o' slot) _1 ps => IsSymbol label => Ord slot => SlotToken ps -> Proxy label -> slot -> Request query a -> HookM m (Maybe a)
Send a query-request to a child of a component at the specified slot. Requires a
token carrying the slot type of the component, which is provided by the
Hooks.component
function.
#tell Source
tell :: forall m label ps query o' slot _1. Cons label (Slot query o' slot) _1 ps => IsSymbol label => Ord slot => SlotToken ps -> Proxy label -> slot -> Tell query -> HookM m Unit
Send a tell-request to a child of a component at the specified slot. Requires a
token carrying the slot type of the component, which is provided by the
Hooks.component
function.
#queryAll Source
queryAll :: forall m label ps query o' slot a _1. Cons label (Slot query o' slot) _1 ps => IsSymbol label => Ord slot => SlotToken ps -> Proxy label -> query a -> HookM m (Map slot a)
Send a query to all children of a component at the specified slot. Requires
a token carrying the slot type of the component, which is provided by the
Hooks.component
function.
#subscribe' Source
subscribe' :: forall m. (SubscriptionId -> Emitter (HookM m Unit)) -> HookM m Unit
An alternative to subscribe
, intended for subscriptions that unsubscribe
themselves. Instead of returning the SubscriptionId
from subscribe'
, it
is passed into an Emitter
constructor. This allows emitted queries
to include the SubscriptionId
, rather than storing it in the state of the
component.
When a component is disposed of any active subscriptions will automatically be stopped and no further subscriptions will be possible during finalization.
#unsubscribe Source
unsubscribe :: forall m. SubscriptionId -> HookM m Unit
Unsubscribes a component from an Emitter
. If the subscription
associated with the ID has already ended this will have no effect.
#fork Source
fork :: forall m. HookM m Unit -> HookM m ForkId
Starts a HalogenM
process running independent from the current eval
"thread".
A commonly use case for fork
is in component initializers where some
async action is started. Normally all interaction with the component will
be blocked until the initializer completes, but if the async action is
fork
ed instead, the initializer can complete synchronously while the
async action continues.
Some care needs to be taken when using a fork
that can modify the
component state, as it's easy for the forked process to "clobber" the state
(overwrite some or all of it with an old value) by mistake.
When a component is disposed of any active forks will automatically be killed. New forks can be started during finalization but there will be no means of killing them.
#getHTMLElementRef Source
getHTMLElementRef :: forall m. RefLabel -> HookM m (Maybe HTMLElement)
Retrieves a HTMLElement
value that is associated with a Ref
in the
rendered o of a component. If there is no currently rendered value (or
it is not an HTMLElement
) for the request will return Nothing
.