Halogen
- Package
- purescript-halogen
- Repository
- purescript-halogen/purescript-halogen
The base Halogen module re-exports most of the library's useful types and
combinators, aside from the HTML
-building functionality - the HTML
modules export a large number of commonly named values that are likely to
conflict.
#HalogenIO Source
type HalogenIO :: (Type -> Type) -> Type -> (Type -> Type) -> Type
type HalogenIO query output m = { dispose :: m Unit, messages :: Emitter output, query :: forall a. query a -> m (Maybe a) }
A record produced when the root component in a Halogen UI has been run.
query
allows external sources to query the root componentmessages
allows external consumers to receive messages raised by the root componentdispose
stops running the UI and finalizes the root component
Re-exports from Data.Lazy
Re-exports from Halogen.Component
#ComponentSpec Source
type ComponentSpec :: Type -> (Type -> Type) -> Type -> Row Type -> Type -> Type -> (Type -> Type) -> Type
type ComponentSpec state query action slots input output m = { eval :: (HalogenQ query action input) ~> (HalogenM state action slots output m), initialState :: input -> state, render :: state -> HTML (ComponentSlot slots m action) action }
The spec for a component.
The type variables involved:
state
is the component's statequery
is the query algebra; the requests that can be made of the componentaction
is the type of actions; messages internal to the component that can be evaluatedslots
is the set of slots for addressing child componentsinput
is the input value that will be received when the parent of this component rendersoutput
is the type of messages the component can raisem
is the effect monad used during evaluation
The values in the record:
initialState
is a function that accepts an input value and produces the state the component will start with. If the input value is unused (Unit
), or irrelevant to the state construction, this will often beconst ?someInitialStateValue
.render
is a function that accepts the component's current state and produces a value to render (HTML
usually). The rendered output can raise actions that will be handled ineval
.eval
is a function that handles theHalogenQ
algebra that deals with component lifecycle, handling actions, and responding to requests.
#ComponentSlotSpec Source
type ComponentSlotSpec :: (Type -> Type) -> Type -> Type -> Row Type -> (Type -> Type) -> Type -> Type
type ComponentSlotSpec query input output slots m action = { component :: Component query input output m, get :: forall slot. SlotStorage slots slot -> Maybe (slot query output), input :: input, output :: output -> Maybe action, pop :: forall slot. SlotStorage slots slot -> Maybe (Tuple (slot query output) (SlotStorage slots slot)), set :: forall slot. slot query output -> SlotStorage slots slot -> SlotStorage slots slot }
The internal representation used for a ComponentSlot
.
#ComponentSlot Source
data ComponentSlot :: Row Type -> (Type -> Type) -> Type -> Type
data ComponentSlot slots m action
Instances
Functor (ComponentSlot slots m)
#Component Source
data Component :: (Type -> Type) -> Type -> Type -> (Type -> Type) -> Type
data Component (query :: Type -> Type) (input :: Type) (output :: Type) (m :: Type -> Type)
The "public" type for a component, with details of the component internals existentially hidden.
HTML
query
is the query algebra; the requests that can be made of the componentinput
is the input value that will be received when the parent of this component rendersoutput
is the type of messages the component can raisem
is the effect monad used during evaluation
#unComponentSlot Source
unComponentSlot :: forall slots m action a. (forall query input output. ComponentSlotSpec query input output slots m action -> a) -> ComponentSlotBox slots m action -> a
Exposes the inner details of a ComponentSlot
to a
function to produce a new result.
The hidden details will not be allowed to be revealed in the result of the function - if any of the hidden types (state, action, set of slots) appear in the result, the compiler will complain about an escaped skolem.
#unComponent Source
unComponent :: forall query input output m a. (forall state action slots. ComponentSpec state query action slots input output m -> a) -> Component query input output m -> a
Exposes the inner details of a Component
to a function
to produce a new result.
The hidden details will not be allowed to be revealed in the result of the function - if any of the hidden types (state, action, set of slots) appear in the result, the compiler will complain about an escaped skolem.
#mkEval Source
mkEval :: forall state query action slots input output m a. EvalSpec state query action slots input output m -> HalogenQ query action input a -> HalogenM state action slots output m a
Accepts an EvalSpec
to produce an eval
function for a component. For
example:
-- use `defaultEval` and override fields selectively
H.mkEval (H.defaultEval { handleAction = ?handleAction })
-- or specify all the fields in the `EvalSpec`
H.mkEval
{ handleAction: ?handleAction
, handleQuery: ?handleQuery
, receive: ?receive
, initialize: ?initialize
, finalize: ?finalize
}
#mkComponent Source
mkComponent :: forall state query action slots input output m. ComponentSpec state query action slots input output m -> Component query input output m
Constructs a Component
from a ComponentSpec
.
#defaultEval Source
defaultEval :: forall state query action slots input output m. EvalSpec state query action slots input output m
A default value for mkEval
that will result in an eval
that nothing at
all - all incoming actions and queries will be ignored, and no receiver,
initializer, or finalizer will be specified.
Usually this will be used with record update syntax to override fields to specify things as needed. If a component only needs to handle actions, for instance, a usage might be something like this:
H.mkComponent
{ initialState
, render
, eval: H.mkEval (H.defaultEval { handleAction = ?handleAction })
}
#componentSlot Source
componentSlot :: forall query input output slots m action label slot _1. Cons label (Slot query output slot) _1 slots => IsSymbol label => Ord slot => Proxy label -> slot -> Component query input output m -> input -> (output -> Maybe action) -> ComponentSlotBox slots m action
Constructs a ComponentSlot
.
Takes:
- the slot address label
- the slot address index
- the component for the slot
- the input value to pass to the component
- a function mapping outputs from the component to a query in the parent
Re-exports from Halogen.Data.Slot
#Slot Source
data Slot :: (Type -> Type) -> Type -> Type -> Type
data Slot (query :: Type -> Type) output slot
A type which records the queries, output messages, and slot identifier for a particular slot (ie. a location in HTML where a component is rendered). For example:
type ButtonSlot slot = Slot Button.Query Button.Output slot
-- A component using this slot type can have one type of child component,
-- which supports `Button.Query` queries, `Button.Output` outputs, and
-- which can be uniquely identified by an integer.
type Slots = ( button :: ButtonSlot Int )
query
represents the requests that can be made of this componentoutput
represents the output messages that can be raised by this componentslot
represents the unique identifier for this component
Re-exports from Halogen.HTML
#ComponentHTML Source
type ComponentHTML :: Type -> Row Type -> (Type -> Type) -> Type
type ComponentHTML action slots m = HTML (ComponentSlot slots m action) action
A convenience synonym for the output type of a render
function for a
component that renders HTML.
action
is the type of actions, events internal to the component that can be evaluated with thehandleAction
functionslots
is the set of child component types that can be used in the HTMLm
is the monad used by the child component during evaluation
Re-exports from Halogen.HTML.Core
Re-exports from Halogen.Query
#Tell Source
type Tell :: (Type -> Type) -> Type
type 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).
#SubscriptionId Source
newtype SubscriptionId
The ID value associated with a subscription. Allows the subscription to be stopped at a later time.
Instances
#Request Source
type Request :: (Type -> Type) -> Type -> Type
type 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)
#HalogenM Source
newtype HalogenM :: Type -> Type -> Row Type -> Type -> (Type -> Type) -> Type -> Type
newtype HalogenM state action slots output m a
The Halogen component eval effect monad.
state
is the component's stateaction
is the type of actions; events internal to the component that can be evaluatedslots
is the set of slots for addressing child componentsoutput
is the type of output messages the component can raisem
is the monad used during evaluationa
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
Functor (HalogenM state action slots output m)
Apply (HalogenM state action slots output m)
Applicative (HalogenM state action slots output m)
Bind (HalogenM state action slots output m)
Monad (HalogenM state action slots output m)
(Semigroup a) => Semigroup (HalogenM state action slots output m a)
(Monoid a) => Monoid (HalogenM state action slots output m a)
(MonadEffect m) => MonadEffect (HalogenM state action slots output m)
(MonadAff m) => MonadAff (HalogenM state action slots output m)
Parallel (HalogenAp state action slots output m) (HalogenM state action slots output m)
MonadTrans (HalogenM state action slots o)
MonadRec (HalogenM state action slots output m)
MonadState state (HalogenM state action slots output m)
(MonadAsk r m) => MonadAsk r (HalogenM state action slots output m)
(MonadTell w m) => MonadTell w (HalogenM state action slots output m)
(MonadThrow e m) => MonadThrow e (HalogenM state action slots output m)
#HalogenF Source
data HalogenF :: Type -> Type -> Row Type -> Type -> (Type -> Type) -> Type -> Type
data HalogenF state action slots output m a
The Halogen component eval algebra.
state
is the component's stateaction
is the type of actions; events internal to the component that can be evaluatedslots
is the set of slots for addressing child componentsoutput
is the type of output messages the component can raisem
is the monad used during evaluationa
is the result of the HalogenF expression (see HalogenM for an example).
Constructors
State (state -> Tuple a state)
Subscribe (SubscriptionId -> Emitter action) (SubscriptionId -> a)
Unsubscribe SubscriptionId a
Lift (m a)
ChildQuery (ChildQueryBox slots a)
Raise output a
Par (HalogenAp state action slots output m a)
Fork (HalogenM state action slots output m Unit) (ForkId -> a)
Join ForkId a
Kill ForkId a
GetRef RefLabel (Maybe Element -> a)
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.
#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.
#liftEffect Source
liftEffect :: forall m a. MonadEffect m => Effect a -> m a
#lift Source
lift :: forall t m a. MonadTrans t => Monad m => m a -> t m a
#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.
#gets Source
gets :: forall s m a. MonadState s m => (s -> a) -> m a
Get a value which depends on the current state.
#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
.
#get Source
get :: forall m s. MonadState s m => m s
Get the current state.
#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
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.
- Modules
- Halogen
- Halogen.
Aff - Halogen.
Aff. Driver - Halogen.
Aff. Driver. Eval - Halogen.
Aff. Driver. State - Halogen.
Aff. Util - Halogen.
Component - Halogen.
Component. Profunctor - Halogen.
Data. OrdBox - Halogen.
Data. Slot - Halogen.
HTML - Halogen.
HTML. Core - Halogen.
HTML. Elements - Halogen.
HTML. Elements. Keyed - Halogen.
HTML. Events - Halogen.
HTML. Properties - Halogen.
HTML. Properties. ARIA - Halogen.
Query - Halogen.
Query. ChildQuery - Halogen.
Query. Event - Halogen.
Query. HalogenM - Halogen.
Query. HalogenQ - Halogen.
Query. Input - Halogen.
VDom. Driver