Module

Halogen.Query

Package
purescript-halogen
Repository
purescript-halogen/purescript-halogen

Functions and types used to describe the HalogenF algebra used in a component's eval function.

#Tell Source

type Tell :: (Type -> Type) -> Typetype Tell f = Unit -> f Unit

Type synonym for a "tell-style" query - queries that only cause effects, but that cannot receive a return value.

In a query algebra, a tell constructor carries the algebra's type variable as its last argument. For example:

data Query a
  = SomeTell a
  | SomeOtherTell String a
  | NotATell (Boolean -> a)

Both SomeTell and SomeOtherTell carry a plain a as a value, whereas NotATell has a as the result of a function so is considered to be a "request" (see below).

#mkTell Source

mkTell :: forall f. Tell f -> f Unit

Takes a data constructor of query algebra f and creates a tell query.

For example:

data Query a = Tick a

sendTick :: forall o. H.HalogenIO Query o Aff -> Aff (Maybe Unit)
sendTick app = app.query (H.mkTell Tick)

#tell Source

tell :: forall state action output m label slots query output' slot _1. Cons label (Slot query output' slot) _1 slots => IsSymbol label => Ord slot => Proxy label -> slot -> Tell query -> HalogenM state action slots output m Unit

#tellAll Source

tellAll :: forall state action output m label slots query output' slot _1. Cons label (Slot query output' slot) _1 slots => IsSymbol label => Ord slot => Proxy label -> Tell query -> HalogenM state action slots output m Unit

#Request Source

type Request :: (Type -> Type) -> Type -> Typetype Request f a = (a -> a) -> f a

Type synonym for an "request-style" query - queries that can cause effects as well as fetching some information from a component.

In a query algebra, a request constructor carries the algebra's type variable as the return value of a function as its last argument. For example:

data Query a = SomeRequest (Boolean -> a)

#mkRequest Source

mkRequest :: forall f a. Request f a -> f a

Takes a data constructor of query algebra f and creates a request query.

For example:

data Query a = GetTickCount (Int -> a)

getTickCount :: forall o. H.HalogenIO Query o Aff -> Aff (Maybe Int)
getTickCount app = app.query (H.mkRequest GetTickCount)

#request Source

request :: forall state action output m label slots query output' slot a _1. Cons label (Slot query output' slot) _1 slots => IsSymbol label => Ord slot => Proxy label -> slot -> Request query a -> HalogenM state action slots output m (Maybe a)

#requestAll Source

requestAll :: forall state action output m label slots query output' slot a _1. Cons label (Slot query output' slot) _1 slots => IsSymbol label => Ord slot => Proxy label -> Request query a -> HalogenM state action slots output m (Map slot a)

#getHTMLElementRef Source

getHTMLElementRef :: forall state action slots output m. RefLabel -> HalogenM state action slots output m (Maybe HTMLElement)

Retrieves a HTMLElement value that is associated with a Ref in the rendered output of a component. If there is no currently rendered value (or it is not an HTMLElement) for the request will return Nothing.

Re-exports from Control.Monad.State.Class

#put Source

put :: forall m s. MonadState s m => s -> m Unit

Set the state.

#modify_ Source

modify_ :: forall s m. MonadState s m => (s -> s) -> m Unit

#modify Source

modify :: forall s m. MonadState s m => (s -> s) -> m s

Modify the state by applying a function to the current state. The returned value is the new state value.

#gets Source

gets :: forall s m a. MonadState s m => (s -> a) -> m a

Get a value which depends on the current state.

#get Source

get :: forall m s. MonadState s m => m s

Get the current state.

Re-exports from Control.Monad.Trans.Class

#lift Source

lift :: forall t m a. MonadTrans t => Monad m => m a -> t m a

Re-exports from Effect.Aff.Class

#liftAff Source

liftAff :: forall m. MonadAff m => Aff ~> m

Re-exports from Effect.Class

#liftEffect Source

liftEffect :: forall m a. MonadEffect m => Effect a -> m a

Re-exports from Halogen.Query.HalogenM

#SubscriptionId Source

newtype SubscriptionId

The ID value associated with a subscription. Allows the subscription to be stopped at a later time.

Instances

#HalogenM Source

newtype HalogenM :: Type -> Type -> Row Type -> Type -> (Type -> Type) -> Type -> Typenewtype HalogenM state action slots output m a

The Halogen component eval effect monad.

  • state is the component's state
  • action is the type of actions; events internal to the component that can be evaluated
  • slots is the set of slots for addressing child components
  • output is the type of output messages the component can raise
  • m is the monad used during evaluation
  • a is the result of the HalogenM expression. Use the following pattern: handleAction :: Action -> H.HalogenM State Action Slots Output m Unit handleQuery :: forall a. Query a -> H.HalogenM State Action Slots Output m (Maybe a)

Constructors

Instances

#HalogenF Source

data HalogenF :: Type -> Type -> Row Type -> Type -> (Type -> Type) -> Type -> Typedata HalogenF state action slots output m a

The Halogen component eval algebra.

  • state is the component's state
  • action is the type of actions; events internal to the component that can be evaluated
  • slots is the set of slots for addressing child components
  • output is the type of output messages the component can raise
  • m is the monad used during evaluation
  • a is the result of the HalogenF expression (see HalogenM for an example).

Constructors

Instances

#ForkId Source

newtype ForkId

The ID value associated with a forked process. Allows the fork to be killed at a later time.

Instances

#unsubscribe Source

unsubscribe :: forall state action slots output m. SubscriptionId -> HalogenM state action slots output m Unit

Unsubscribes a component from a subscription. If the subscription associated with the ID has already ended this will have no effect.

#subscribe' Source

subscribe' :: forall state action slots output m. (SubscriptionId -> Emitter action) -> HalogenM state action slots output 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.

#subscribe Source

subscribe :: forall state action slots output m. Emitter action -> HalogenM state action slots output m SubscriptionId

Subscribes a component to an Emitter.

When a component is disposed of any active subscriptions will automatically be stopped and no further subscriptions will be possible during finalization.

#raise Source

raise :: forall state action slots output m. output -> HalogenM state action slots output m Unit

Raises an output message for the component.

#queryAll Source

queryAll :: forall state action output m label slots query output' slot a _1. Cons label (Slot query output' slot) _1 slots => IsSymbol label => Ord slot => Proxy label -> query a -> HalogenM state action slots output m (Map slot a)

Sends a query to all children of a component at a given slot label.

#query Source

query :: forall state action output m label slots query output' slot a _1. Cons label (Slot query output' slot) _1 slots => IsSymbol label => Ord slot => Proxy label -> slot -> query a -> HalogenM state action slots output m (Maybe a)

Sends a query to a child of a component at the specified slot.

#kill Source

kill :: forall state action slots output m. ForkId -> HalogenM state action slots output m Unit

Kills a forked process if it is still running. Attempting to kill a forked process that has already ended will have no effect.

#join Source

join :: forall state action slots output m. ForkId -> HalogenM state action slots output m Unit

Joins a forked process. Attempting to join a forked process that has already ended will result in eval continuing immediately. Attempting to join a forked process that has been killed will also terminate the current eval.

#getRef Source

getRef :: forall state action slots output m. RefLabel -> HalogenM state action slots output m (Maybe Element)

Retrieves an Element value that is associated with a Ref in the rendered output of a component. If there is no currently rendered value for the requested ref this will return Nothing.

#fork Source

fork :: forall state action slots output m. HalogenM state action slots output m Unit -> HalogenM state action slots output 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 forked 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.

Re-exports from Halogen.Query.HalogenQ

#HalogenQ Source

data HalogenQ :: (Type -> Type) -> Type -> Type -> Type -> Typedata HalogenQ query action input a

Constructors

Instances

Re-exports from Halogen.Query.Input

#RefLabel Source