Module

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

type HalogenIO f o m = { query :: f ~> m, subscribe :: Consumer o m Unit -> m Unit }

A record produced when the root component in a Halogen UI has been run. query allows external sources to query the root component and subscribe allows external consumers to receive messages raised by the root component.

#HTML

type HTML p i = HTML p (i Unit)

A specialised version of the Halogen.HTML.Core.HTML type where i is * -> * kinded to match the kind of a component query algebra.

#IProp

type IProp r i = IProp r (i Unit)

A specialised version of the Halogen.HTML.Properties.IProp type where i is * -> * kinded to match the kind of a component query algebra.

Re-exports from Data.Lazy

#defer

defer :: forall a. (Unit -> a) -> Lazy a

Defer a computation, creating a Lazy value.

Re-exports from Halogen.Component

#ParentLifecycleComponentSpec

type ParentLifecycleComponentSpec h s f g p i o m = { initialState :: i -> s, render :: s -> h (ComponentSlot h g m p (f Unit)) (f Unit), eval :: f ~> (HalogenM s f g p o m), receiver :: i -> Maybe (f Unit), initializer :: Maybe (f Unit), finalizer :: Maybe (f Unit) }

A spec for a parent component, including lifecycle inputs.

  • h is the type that will be rendered by the component, usually HTML
  • s is the component's state
  • f is the query algebra for the component itself
  • g is the query algebra for child components
  • p is the slot type for addressing child components
  • o is the type for the component's output messages
  • m is the monad used for non-component-state effects

#ParentHTML

type ParentHTML f g p m = HTML (ComponentSlot HTML g m p (f Unit)) (f Unit)

A convenience synonym for the output type of a render function, for a parent component that renders HTML.

#ParentDSL

type ParentDSL = HalogenM

A synonym for just HalogenM. Provided for consistency with ComponentDSL in the non-parent-component case.

#ParentComponentSpec

type ParentComponentSpec h s f g p i o m = { initialState :: i -> s, render :: s -> h (ComponentSlot h g m p (f Unit)) (f Unit), eval :: f ~> (HalogenM s f g p o m), receiver :: i -> Maybe (f Unit) }

A spec for a component.

  • h is the type that will be rendered by the component, usually HTML
  • s is the component's state
  • f is the query algebra for the component itself
  • g is the query algebra for child components
  • p is the slot type for addressing child components
  • o is the type for the component's output messages
  • m is the monad used for non-component-state effects

#LifecycleComponentSpec

type LifecycleComponentSpec h s f i o m = { initialState :: i -> s, render :: s -> h Void (f Unit), eval :: f ~> (ComponentDSL s f o m), receiver :: i -> Maybe (f Unit), initializer :: Maybe (f Unit), finalizer :: Maybe (f Unit) }

A spec for a component with no possible children, including lifecycle inputs.

  • h is the type that will be rendered by the component, usually HTML
  • s is the component's state
  • f is the query algebra
  • i is the input value type that will be mapped to an f whenever the parent of this component renders
  • o is the type for the component's output messages
  • m is the monad used for non-component-state effects

#ComponentSpec

type ComponentSpec h s f i o m = { initialState :: i -> s, render :: s -> h Void (f Unit), eval :: f ~> (ComponentDSL s f o m), receiver :: i -> Maybe (f Unit) }

A spec for a component with no possible children.

  • h is the type that will be rendered by the component, usually HTML
  • s is the component's state
  • f is the query algebra
  • i is the input value type that will be mapped to an f whenever the parent of this component renders
  • o is the type for the component's output messages
  • m is the monad used for non-component-state effects

#ComponentSlot

data ComponentSlot (h :: Type -> Type -> Type) (g :: Type -> Type) (m :: Type -> Type) p q

Instances

#ComponentHTML

type ComponentHTML f = HTML Void (f Unit)

A convenience synonym for the output type of a render function, for a childless component that renders HTML.

#ComponentDSL

type ComponentDSL s f = HalogenM s f (Const Void) Void

A synonym for HalogenM with some type parameters populated that are not relevant for childless components.

#Component'

type Component' h s f g p i o m = { initialState :: i -> s, render :: s -> h (ComponentSlot h g m p (f Unit)) (f Unit), eval :: f ~> (HalogenM s f g p o m), receiver :: i -> Maybe (f Unit), initializer :: Maybe (f Unit), finalizer :: Maybe (f Unit), mkOrdBox :: p -> OrdBox p }

The "private" type for a component.

  • h is the type that will be rendered by the component, usually HTML
  • s is the component's state
  • f is the query algebra for the component itself
  • g is the query algebra for child components
  • p is the slot type for addressing child components
  • i is the input value type that will be mapped to an f whenever the parent of this component renders
  • o is the type for the component's output messages
  • m is the monad used for non-component-state effects

#Component

data Component (h :: Type -> Type -> Type) (f :: Type -> Type) i o (m :: Type -> Type)

The "public" type for a component, with details of the component internals existentially hidden.

  • h is the type that will be rendered by the component, usually HTML
  • f is the query algebra
  • i is the input value type that will be mapped to an f whenever the parent of this component renders
  • o is the type for the component's output messages
  • m is the monad used for non-component-state effects

#unComponentSlot

unComponentSlot :: forall h g m p q r. (forall z j o. p -> Component h z j o m -> j -> (j -> Maybe (g Unit)) -> (o -> Maybe q) -> (forall x. g x -> Maybe (z x)) -> r) -> ComponentSlot h g m p q -> r

#unComponent

unComponent :: forall h f i o m r. (forall s g p. Component' h s f g p i o m -> r) -> Component h f i o m -> r

Exposes the inner details of a component to a function to produce a new result. The inner details will not be allowed to be revealed in the result of the function - the compiler will complain about an escaped skolem.

#parentComponent

parentComponent :: forall h s f g p i o m. Ord p => ParentComponentSpec h s f g p i o m -> Component h f i o m

Builds a component that allows for children.

#mkComponentSlot

mkComponentSlot :: forall h g z m p j q o. p -> (Component h z j o m) -> j -> (j -> Maybe (g Unit)) -> (o -> Maybe q) -> (forall x. g x -> Maybe (z x)) -> ComponentSlot h g m p q

#mkComponent

mkComponent :: forall h s f g p i o m. Component' h s f g p i o m -> Component h f i o m

Makes a Component from a Component', existentially hiding details about the component's state and potential children.

#lifecycleParentComponent

lifecycleParentComponent :: forall h s f g p i o m. Ord p => ParentLifecycleComponentSpec h s f g p i o m -> Component h f i o m

Builds a component with lifecycle inputs that allows for children.

#lifecycleComponent

lifecycleComponent :: forall h s f i o m. Bifunctor h => LifecycleComponentSpec h s f i o m -> Component h f i o m

Builds a component with lifecycle inputs and no possible children.

#hoist

hoist :: forall h f i o m m'. Bifunctor h => Functor m' => (m ~> m') -> Component h f i o m -> Component h f i o m'

Changes the component's m type. A use case for this would be to interpret some Free monad as Aff so the component can be used with runUI.

#component

component :: forall h s f i o m. Bifunctor h => ComponentSpec h s f i o m -> Component h f i o m

Builds a component with no possible children.

Re-exports from Halogen.HTML.Core

#PropName

newtype PropName value

A type-safe wrapper for property names.

The phantom type value describes the type of value which this property requires.

Constructors

Instances

#Namespace

#ElemName

#ClassName

newtype ClassName

A wrapper for strings which are used as CSS classes.

Constructors

Instances

#AttrName

newtype AttrName

A type-safe wrapper for attribute names.

Constructors

Instances

Re-exports from Halogen.Query

#SubscribeStatus

data SubscribeStatus

The status of an EventSource subscription. When a query raised by an EventSource evaluates to Done the producer will be unsubscribed from.

Constructors

Instances

#Request

type Request f a = (a -> a) -> f a

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

In a query algebra, an action is any constructor that carries the algebra's type variable as the return value of a function. For example:

data Query a = SomeRequest (Boolean -> a)

#RefLabel

#HalogenM

newtype HalogenM s (f :: Type -> Type) g p o m a

Constructors

Instances

#HalogenF

data HalogenF s (f :: Type -> Type) g p o m a

The Halogen component algebra

Constructors

Instances

#EventSource

newtype EventSource f m

#Action

type Action f = Unit -> f Unit

Type synonym for an "action" - An action only causes effects and has no result value.

In a query algebra, an action is any constructor that carries the algebra's type variable as a value. For example:

data Query a
  = SomeAction a
  | SomeOtherAction String a
  | NotAnAction (Boolean -> a)

Both SomeAction and SomeOtherAction have a as a value so they are considered actions, whereas NotAnAction has a as the result of a function so is considered to be a "request" (see below).

#subscribe

subscribe :: forall s f g p o m. EventSource f m -> HalogenM s f g p o m Unit

Provides a way of having a component subscribe to an EventSource from within an Eval function.

#request

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

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

For example:

data Query a = GetTickCount (Int -> a)

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

#raise

raise :: forall s f g p o m. o -> HalogenM s f g p o m Unit

Raises an output message for the component.

#queryAll'

queryAll' :: forall s f g g' p p' o m a. Ord p => Eq p' => ChildPath g g' p p' -> g a -> HalogenM s f g' p' o m (Map p a)

Sends a query to all children of a specific type within a component, using a ChildPath to discriminate the type of child component to query.

#queryAll

queryAll :: forall s f g p o m a. Ord p => g a -> HalogenM s f g p o m (Map p a)

Sends a query to all children of a component.

#query'

query' :: forall s f g g' m p p' o a. Eq p' => ChildPath g g' p p' -> p -> g a -> HalogenM s f g' p' o m (Maybe a)

Sends a query to a child of a component at the specified slot, using a ChildPath to discriminate the type of child component to query.

#query

query :: forall s f g p o m a. Eq p => p -> g a -> HalogenM s f g p o m (Maybe a)

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

#put

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

Set the state.

#modify_

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

#modify

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.

#mkQuery

mkQuery :: forall s f g p o m a. Eq p => p -> g a -> HalogenM s f g p o m a

#liftEffect

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

#liftAff

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

#lift

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

#gets

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

Get a value which depends on the current state.

#getSlots

getSlots :: forall s f g p o m. HalogenM s f g p o m (List p)

#getRef

getRef :: forall s f g p o m. RefLabel -> HalogenM s f g p o m (Maybe Element)

#getHTMLElementRef

getHTMLElementRef :: forall s f g p o m. RefLabel -> HalogenM s f g p o m (Maybe HTMLElement)

#get

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

Get the current state.

#fork

fork :: forall s f g p o m a. MonadAff m => HalogenM s f g p o m a -> HalogenM s f g p o m (Error -> m Unit)

#eventSource_

eventSource_ :: forall f m. MonadAff m => (Effect Unit -> Effect Unit) -> f SubscribeStatus -> EventSource f m

Creates an EventSource for a callback that accepts no arguments.

  • The first argument is the function that attaches the listener.
  • The second argument is the query to raise whenever the listener is triggered.

#eventSource

eventSource :: forall f m a. MonadAff m => ((a -> Effect Unit) -> Effect Unit) -> (a -> Maybe (f SubscribeStatus)) -> EventSource f m

Creates an EventSource for a callback that accepts one argument.

  • The first argument is the function that attaches the listener.
  • The second argument is a handler that optionally produces a value in f.

#checkSlot

checkSlot :: forall s f g p o m. p -> HalogenM s f g p o m Boolean

#action

action :: forall f. Action f -> f Unit

Takes a data constructor of query algebra f and creates an action.

For example:

data Query a = Tick a

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

Modules