Halogen.Component
- Package
- purescript-halogen
- Repository
- purescript-halogen/purescript-halogen
#Component Source
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
queryis 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 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:
stateis 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 state query action slots input output m. ComponentSpec state query action slots input output m -> Component query input output mConstructs a Component from a ComponentSpec.
#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 -> 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.
#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 state query action slots input output m. 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:
-- 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 state query action slots input output m. 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 })
}
#ComponentSlotBox Source
data ComponentSlotBox (slots :: Row Type) (m :: Type -> Type) (action :: Type)A slot for a child component in a component's rendered content.
Instances
Functor (ComponentSlotBox slots m)
#ComponentSlot Source
data ComponentSlot slots m actionConstructors
ComponentSlot (ComponentSlotBox slots m action)ThunkSlot (Thunk (HTML (ComponentSlot slots m action)) action)
Instances
Functor (ComponentSlot slots m)
#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 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 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.
#mkComponentSlot Source
mkComponentSlot :: forall query input output slots m action. ComponentSlotSpec query input output slots m action -> ComponentSlotBox slots m actionConstructs ComponentSlotBox from a ComponentSlotSpec.
#unComponentSlot Source
unComponentSlot :: forall slots m action a. (forall query input output. ComponentSlotSpec query input output slots m action -> a) -> ComponentSlotBox 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 slots m m' action. Functor m' => (m ~> m') -> ComponentSlot slots m action -> ComponentSlot 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. Event - Halogen.
Query. HalogenM - Halogen.
Query. HalogenQ - Halogen.
Query. Input - Halogen.
VDom. Driver