Halogen.Component
- Package
- purescript-halogen
- Repository
- purescript-halogen/purescript-halogen
#Component Source
data Component (surface :: Type -> Type -> Type) (query :: Type -> Type) (input :: Type) (output :: Type) (m :: Type -> Type)The "public" type for a component, with details of the component internals existentially hidden.
surfaceis the type that will be rendered by the component, usuallyHTMLqueryis the query algebra; the requests that can be made of the componentinputis the input value that will be received when the parent of this component rendersoutputis the type of messages the component can raisemis the effect monad used during evaluation
#ComponentSpec Source
type ComponentSpec surface state query action slots input output m = { eval :: (HalogenQ query action input) ~> (HalogenM state action slots output m), initialState :: input -> state, render :: state -> surface (ComponentSlot surface slots m action) action }The spec for a component.
The type variables involved:
surfaceis the type that will be rendered by the component, usuallyHTMLstateis the component's statequeryis the query algebra; the requests that can be made of the componentactionis the type of actions; messages internal to the component that can be evaluatedslotsis the set of slots for addressing child componentsinputis the input value that will be received when the parent of this component rendersoutputis the type of messages the component can raisemis the effect monad used during evaluation
The values in the record:
initialStateis 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.renderis a function that accepts the component's current state and produces a value to render (HTMLusually). The rendered output can raise actions that will be handled ineval.evalis a function that handles theHalogenQalgebra that deals with component lifecycle, handling actions, and responding to requests.
#mkComponent Source
mkComponent :: forall m output input slots action query state surface. ComponentSpec surface state query action slots input output m -> Component surface query input output mConstructs a Component from a ComponentSpec.
#unComponent Source
unComponent :: forall a m output input query surface. (forall slots action state. ComponentSpec surface state query action slots input output m -> a) -> Component surface query input output m -> aExposes 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.
#hoist Source
hoist :: forall m' m output input query surface. Bifunctor surface => Functor m' => (m ~> m') -> Component surface query input output m -> Component surface query input output m'Changes the Component's m type. A use case for this
might be to interpret some Free monad as Aff so the component can be
used with runUI.
#EvalSpec Source
type EvalSpec state query action slots input output m = { finalize :: Maybe action, handleAction :: action -> HalogenM state action slots output m Unit, handleQuery :: forall a. query a -> HalogenM state action slots output m (Maybe a), initialize :: Maybe action, receive :: input -> Maybe action }The spec record that mkEval accepts to construct a component eval
function.
It's not a requirement to use mkEval, and sometimes it's preferrable
to write a component eval function from scratch, but often mkEval is
more convenient for common cases.
See below for more details about mkEval and defaultEval.
#mkEval Source
mkEval :: forall m output input slots action query state. EvalSpec state query action slots input output m -> (HalogenQ query action input) ~> (HalogenM state action slots output m)Accepts an EvalSpec to produce an eval function for a component. For
example:
``purescript
-- 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
}
#defaultEval Source
defaultEval :: forall m output input slots action query state. EvalSpec state query action slots input output mA 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
data ComponentSlot surface slots m actionConstructors
ComponentSlot (ComponentSlotBox surface slots m action)ThunkSlot (Thunk (surface (ComponentSlot surface slots m action)) action)
Instances
(Bifunctor surface) => Functor (ComponentSlot surface slots m)
#componentSlot Source
componentSlot :: forall _1 slot label action m slots output input query surface. Cons label (Slot query output slot) _1 slots => IsSymbol label => Ord slot => SProxy label -> slot -> Component surface query input output m -> input -> (output -> Maybe action) -> ComponentSlotBox surface slots m actionConstructs 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
#ComponentSlotSpec Source
type ComponentSlotSpec surface query input output slots m action = { component :: Component surface 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.
#mkComponentSlot Source
mkComponentSlot :: forall action m slots output input query surface. ComponentSlotSpec surface query input output slots m action -> ComponentSlotBox surface slots m actionConstructs ComponentSlotBox from a ComponentSlotSpec.
#unComponentSlot Source
unComponentSlot :: forall a action m slots surface. (forall output input query. ComponentSlotSpec surface query input output slots m action -> a) -> ComponentSlotBox surface slots m action -> aExposes 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.
#hoistSlot Source
hoistSlot :: forall action m' m slots surface. Bifunctor surface => Functor m' => (m ~> m') -> ComponentSlot surface slots m action -> ComponentSlot surface slots m' actionChanges the ComponentSlot's m type.
- 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. EventSource - Halogen.
Query. HalogenM - Halogen.
Query. HalogenQ - Halogen.
Query. Input - Halogen.
VDom. Driver