Functions and types used to describe the HalogenF algebra used in a
component's eval and peek functions.
type Action f = Unit -> f UnitType 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).
action :: forall f. Action f -> f UnitTakes a data constructor of query algebra f and creates an action.
For example:
data Query a = Tick a
sendTick :: forall eff. Driver Query eff -> Aff (HalogenEffects eff) Unit
sendTick driver = driver (action Tick)type Request f a = forall i. (a -> i) -> f iType 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)request :: forall f a. Request f a -> f aTakes a data constructor of query algebra f and creates a request.
For example:
data Query a = GetTickCount (Int -> a)
getTickCount :: forall eff. Driver Query eff -> Aff (HalogenEffects eff) Int
getTickCount driver = driver (request GetTickCount)data HalogenF s f g a
= StateHF (StateF s a)
| SubscribeHF (SubscribeF f g a)
| QueryHF (g a)
| HaltHFThe Halogen component algebra
instance functorHalogenF :: (Functor g) => Functor (HalogenF s f g)
instance injectStateHF :: Inject (StateF s) (HalogenF s f g)
instance injectSubscribeHF :: Inject (SubscribeF f g) (HalogenF s f g)
instance injectQueryHF :: Inject g (HalogenF s f g)
instance altHalogenF :: (Functor g) => Alt (HalogenF s f g)
instance plusHalogenF :: (Functor g) => Plus (HalogenF s f g)get :: forall s f g. Free (HalogenF s f g) sProvides a way of accessing the current component's state within an Eval
or Peek function. This is much like get for the State monad, but
instead of operating in some StateT, uses the HalogenF algebra. For
example:
data Query a = GetState (State -> a)
eval :: forall g. Eval Query State Query g
eval (GetState k) = do
currentState <- get
pure (k currentState)gets :: forall s f g a. (s -> a) -> Free (HalogenF s f g) aA version of get that maps over the retrieved state before
returning the result. Useful in cases where only a portion of the state is
desired. For example:
data Query a = GetX (Number -> a)
type State = { x :: Number, y :: Number }
eval :: forall g. Eval Query State Query g
eval (GetX k) = do
x <- gets _.x
pure (k x)modify :: forall s f g. (s -> s) -> Free (HalogenF s f g) UnitProvides a way of modifying the current component's state within an Eval
or Peek function. This is much like modify for the State monad, but
instead of operating in some StateT, uses the HalogenF algebra. For
example:
data Query a = Increment a
type State = Int
eval :: forall g. Eval Query State Query g
eval (Increment next) = do
modify (+ 1)
pure nextsubscribe :: forall s f g. EventSource f g -> Free (HalogenF s f g) UnitProvides a way of having a component subscribe to an EventSource from
within an Eval or Peek function.
liftH :: forall a s f g. g a -> Free (HalogenF s f g) aA convenience function for lifting a g value directly into
Free HalogenF without the need to use liftF $ right $ right $ ....
liftAff' :: forall eff a s f g. (MonadAff eff g, Functor g) => Aff eff a -> Free (HalogenF s f g) aA convenience function for lifting an Aff action directly into a
Free HalogenF when there is a MonadAff instance for the current g,
without the need to use liftH $ liftAff $ ....
liftEff' :: forall eff a s f g. (MonadEff eff g, Functor g) => Eff eff a -> Free (HalogenF s f g) aA convenience function for lifting an Eff action directly into a
Free HalogenF when there is a MonadEff instance for the current g,
without the need to use liftH $ liftEff $ ....
transformHF :: forall s s' f f' g g'. (Functor g, Functor g') => Natural (StateF s) (StateF s') -> Natural f f' -> Natural g g' -> Natural (HalogenF s f g) (HalogenF s' f' g')Change all the parameters of HalogenF.
hoistHalogenF :: forall s f g h. (Functor h) => Natural g h -> Natural (HalogenF s f g) (HalogenF s f h)Changes the g for a HalogenF. Used internally by Halogen.