module Halogen.Query.HalogenM where

import Control.Applicative.Free.Fast
import Control.Monad.Free.Church
import Control.Monad.Parallel
import Data.Map.Strict qualified as M
import Data.NT
import Data.Row
import HPrelude hiding (Ap)
import Halogen.Data.Slot as Slot
import Halogen.Query.ChildQuery qualified as CQ
import Halogen.Query.Input
import Halogen.Subscription hiding (Subscribe)
import Halogen.Subscription qualified as HS
import Web.DOM.Element

newtype SubscriptionId = SubscriptionId Int
  deriving newtype (SubscriptionId -> SubscriptionId -> Bool
(SubscriptionId -> SubscriptionId -> Bool)
-> (SubscriptionId -> SubscriptionId -> Bool) -> Eq SubscriptionId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SubscriptionId -> SubscriptionId -> Bool
== :: SubscriptionId -> SubscriptionId -> Bool
$c/= :: SubscriptionId -> SubscriptionId -> Bool
/= :: SubscriptionId -> SubscriptionId -> Bool
Eq, Eq SubscriptionId
Eq SubscriptionId =>
(SubscriptionId -> SubscriptionId -> Ordering)
-> (SubscriptionId -> SubscriptionId -> Bool)
-> (SubscriptionId -> SubscriptionId -> Bool)
-> (SubscriptionId -> SubscriptionId -> Bool)
-> (SubscriptionId -> SubscriptionId -> Bool)
-> (SubscriptionId -> SubscriptionId -> SubscriptionId)
-> (SubscriptionId -> SubscriptionId -> SubscriptionId)
-> Ord SubscriptionId
SubscriptionId -> SubscriptionId -> Bool
SubscriptionId -> SubscriptionId -> Ordering
SubscriptionId -> SubscriptionId -> SubscriptionId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SubscriptionId -> SubscriptionId -> Ordering
compare :: SubscriptionId -> SubscriptionId -> Ordering
$c< :: SubscriptionId -> SubscriptionId -> Bool
< :: SubscriptionId -> SubscriptionId -> Bool
$c<= :: SubscriptionId -> SubscriptionId -> Bool
<= :: SubscriptionId -> SubscriptionId -> Bool
$c> :: SubscriptionId -> SubscriptionId -> Bool
> :: SubscriptionId -> SubscriptionId -> Bool
$c>= :: SubscriptionId -> SubscriptionId -> Bool
>= :: SubscriptionId -> SubscriptionId -> Bool
$cmax :: SubscriptionId -> SubscriptionId -> SubscriptionId
max :: SubscriptionId -> SubscriptionId -> SubscriptionId
$cmin :: SubscriptionId -> SubscriptionId -> SubscriptionId
min :: SubscriptionId -> SubscriptionId -> SubscriptionId
Ord, Int -> SubscriptionId -> ShowS
[SubscriptionId] -> ShowS
SubscriptionId -> String
(Int -> SubscriptionId -> ShowS)
-> (SubscriptionId -> String)
-> ([SubscriptionId] -> ShowS)
-> Show SubscriptionId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SubscriptionId -> ShowS
showsPrec :: Int -> SubscriptionId -> ShowS
$cshow :: SubscriptionId -> String
show :: SubscriptionId -> String
$cshowList :: [SubscriptionId] -> ShowS
showList :: [SubscriptionId] -> ShowS
Show)

newtype ForkId = ForkId Int
  deriving newtype (ForkId -> ForkId -> Bool
(ForkId -> ForkId -> Bool)
-> (ForkId -> ForkId -> Bool) -> Eq ForkId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ForkId -> ForkId -> Bool
== :: ForkId -> ForkId -> Bool
$c/= :: ForkId -> ForkId -> Bool
/= :: ForkId -> ForkId -> Bool
Eq, Eq ForkId
Eq ForkId =>
(ForkId -> ForkId -> Ordering)
-> (ForkId -> ForkId -> Bool)
-> (ForkId -> ForkId -> Bool)
-> (ForkId -> ForkId -> Bool)
-> (ForkId -> ForkId -> Bool)
-> (ForkId -> ForkId -> ForkId)
-> (ForkId -> ForkId -> ForkId)
-> Ord ForkId
ForkId -> ForkId -> Bool
ForkId -> ForkId -> Ordering
ForkId -> ForkId -> ForkId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ForkId -> ForkId -> Ordering
compare :: ForkId -> ForkId -> Ordering
$c< :: ForkId -> ForkId -> Bool
< :: ForkId -> ForkId -> Bool
$c<= :: ForkId -> ForkId -> Bool
<= :: ForkId -> ForkId -> Bool
$c> :: ForkId -> ForkId -> Bool
> :: ForkId -> ForkId -> Bool
$c>= :: ForkId -> ForkId -> Bool
>= :: ForkId -> ForkId -> Bool
$cmax :: ForkId -> ForkId -> ForkId
max :: ForkId -> ForkId -> ForkId
$cmin :: ForkId -> ForkId -> ForkId
min :: ForkId -> ForkId -> ForkId
Ord, Int -> ForkId -> ShowS
[ForkId] -> ShowS
ForkId -> String
(Int -> ForkId -> ShowS)
-> (ForkId -> String) -> ([ForkId] -> ShowS) -> Show ForkId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ForkId -> ShowS
showsPrec :: Int -> ForkId -> ShowS
$cshow :: ForkId -> String
show :: ForkId -> String
$cshowList :: [ForkId] -> ShowS
showList :: [ForkId] -> ShowS
Show)

data HalogenF state action slots output m a
  = State (state -> (a, state))
  | Subscribe (SubscriptionId -> Emitter IO action) (SubscriptionId -> a)
  | Unsubscribe SubscriptionId a
  | Lift (m a)
  | Unlift (UnliftIO (HalogenM state action slots output m) -> IO a)
  | ChildQuery (CQ.ChildQuery slots a)
  | Raise output a
  | Par (HalogenAp state action slots output m a)
  | Fork (HalogenM state action slots output m ()) (ForkId -> a)
  | Join ForkId a
  | Kill ForkId a
  | GetRef RefLabel (Maybe Element -> a)
  deriving ((forall a b.
 (a -> b)
 -> HalogenF state action slots output m a
 -> HalogenF state action slots output m b)
-> (forall a b.
    a
    -> HalogenF state action slots output m b
    -> HalogenF state action slots output m a)
-> Functor (HalogenF state action slots output m)
forall a b.
a
-> HalogenF state action slots output m b
-> HalogenF state action slots output m a
forall a b.
(a -> b)
-> HalogenF state action slots output m a
-> HalogenF state action slots output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
Functor m =>
a
-> HalogenF state action slots output m b
-> HalogenF state action slots output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
Functor m =>
(a -> b)
-> HalogenF state action slots output m a
-> HalogenF state action slots output m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
Functor m =>
(a -> b)
-> HalogenF state action slots output m a
-> HalogenF state action slots output m b
fmap :: forall a b.
(a -> b)
-> HalogenF state action slots output m a
-> HalogenF state action slots output m b
$c<$ :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
Functor m =>
a
-> HalogenF state action slots output m b
-> HalogenF state action slots output m a
<$ :: forall a b.
a
-> HalogenF state action slots output m b
-> HalogenF state action slots output m a
Functor)

newtype HalogenM state action slots output m a
  = HalogenM (F (HalogenF state action slots output m) a)
  deriving ((forall a b.
 (a -> b)
 -> HalogenM state action slots output m a
 -> HalogenM state action slots output m b)
-> (forall a b.
    a
    -> HalogenM state action slots output m b
    -> HalogenM state action slots output m a)
-> Functor (HalogenM state action slots output m)
forall a b.
a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m a
forall a b.
(a -> b)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
(a -> b)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
(a -> b)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
fmap :: forall a b.
(a -> b)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
$c<$ :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m a
<$ :: forall a b.
a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m a
Functor, Functor (HalogenM state action slots output m)
Functor (HalogenM state action slots output m) =>
(forall a. a -> HalogenM state action slots output m a)
-> (forall a b.
    HalogenM state action slots output m (a -> b)
    -> HalogenM state action slots output m a
    -> HalogenM state action slots output m b)
-> (forall a b c.
    (a -> b -> c)
    -> HalogenM state action slots output m a
    -> HalogenM state action slots output m b
    -> HalogenM state action slots output m c)
-> (forall a b.
    HalogenM state action slots output m a
    -> HalogenM state action slots output m b
    -> HalogenM state action slots output m b)
-> (forall a b.
    HalogenM state action slots output m a
    -> HalogenM state action slots output m b
    -> HalogenM state action slots output m a)
-> Applicative (HalogenM state action slots output m)
forall a. a -> HalogenM state action slots output m a
forall a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m a
forall a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m b
forall a b.
HalogenM state action slots output m (a -> b)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
forall a b c.
(a -> b -> c)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m c
forall state action (slots :: Row (*)) output (m :: * -> *).
Functor (HalogenM state action slots output m)
forall state action (slots :: Row (*)) output (m :: * -> *) a.
a -> HalogenM state action slots output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m (a -> b)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a b c.
(a -> b -> c)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall state action (slots :: Row (*)) output (m :: * -> *) a.
a -> HalogenM state action slots output m a
pure :: forall a. a -> HalogenM state action slots output m a
$c<*> :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m (a -> b)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
<*> :: forall a b.
HalogenM state action slots output m (a -> b)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
$cliftA2 :: forall state action (slots :: Row (*)) output (m :: * -> *) a b c.
(a -> b -> c)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m c
liftA2 :: forall a b c.
(a -> b -> c)
-> HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m c
$c*> :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m b
*> :: forall a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m b
$c<* :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m a
<* :: forall a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m a
Applicative, Applicative (HalogenM state action slots output m)
Applicative (HalogenM state action slots output m) =>
(forall a b.
 HalogenM state action slots output m a
 -> (a -> HalogenM state action slots output m b)
 -> HalogenM state action slots output m b)
-> (forall a b.
    HalogenM state action slots output m a
    -> HalogenM state action slots output m b
    -> HalogenM state action slots output m b)
-> (forall a. a -> HalogenM state action slots output m a)
-> Monad (HalogenM state action slots output m)
forall a. a -> HalogenM state action slots output m a
forall a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m b
forall a b.
HalogenM state action slots output m a
-> (a -> HalogenM state action slots output m b)
-> HalogenM state action slots output m b
forall state action (slots :: Row (*)) output (m :: * -> *).
Applicative (HalogenM state action slots output m)
forall state action (slots :: Row (*)) output (m :: * -> *) a.
a -> HalogenM state action slots output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m a
-> (a -> HalogenM state action slots output m b)
-> HalogenM state action slots output m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m a
-> (a -> HalogenM state action slots output m b)
-> HalogenM state action slots output m b
>>= :: forall a b.
HalogenM state action slots output m a
-> (a -> HalogenM state action slots output m b)
-> HalogenM state action slots output m b
$c>> :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m b
>> :: forall a b.
HalogenM state action slots output m a
-> HalogenM state action slots output m b
-> HalogenM state action slots output m b
$creturn :: forall state action (slots :: Row (*)) output (m :: * -> *) a.
a -> HalogenM state action slots output m a
return :: forall a. a -> HalogenM state action slots output m a
Monad)

instance MonadTrans (HalogenM state' action slots' output) where
  lift :: forall (m :: * -> *) a.
Monad m =>
m a -> HalogenM state' action slots' output m a
lift = F (HalogenF state' action slots' output m) a
-> HalogenM state' action slots' output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state' action slots' output m) a
 -> HalogenM state' action slots' output m a)
-> (m a -> F (HalogenF state' action slots' output m) a)
-> m a
-> HalogenM state' action slots' output m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HalogenF state' action slots' output m a
-> F (HalogenF state' action slots' output m) a
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state' action slots' output m a
 -> F (HalogenF state' action slots' output m) a)
-> (m a -> HalogenF state' action slots' output m a)
-> m a
-> F (HalogenF state' action slots' output m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> HalogenF state' action slots' output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
m a -> HalogenF state action slots output m a
Lift

instance (MonadIO m) => MonadIO (HalogenM state' action slots' output m) where
  liftIO :: forall a. IO a -> HalogenM state' action slots' output m a
liftIO = F (HalogenF state' action slots' output m) a
-> HalogenM state' action slots' output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state' action slots' output m) a
 -> HalogenM state' action slots' output m a)
-> (IO a -> F (HalogenF state' action slots' output m) a)
-> IO a
-> HalogenM state' action slots' output m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HalogenF state' action slots' output m a
-> F (HalogenF state' action slots' output m) a
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state' action slots' output m a
 -> F (HalogenF state' action slots' output m) a)
-> (IO a -> HalogenF state' action slots' output m a)
-> IO a
-> F (HalogenF state' action slots' output m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> HalogenF state' action slots' output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
m a -> HalogenF state action slots output m a
Lift (m a -> HalogenF state' action slots' output m a)
-> (IO a -> m a)
-> IO a
-> HalogenF state' action slots' output m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO

instance (MonadUnliftIO m) => MonadUnliftIO (HalogenM state' action slots' output m) where
  withRunInIO :: forall b.
((forall a. HalogenM state' action slots' output m a -> IO a)
 -> IO b)
-> HalogenM state' action slots' output m b
withRunInIO (forall a. HalogenM state' action slots' output m a -> IO a)
-> IO b
inner =
    F (HalogenF state' action slots' output m) b
-> HalogenM state' action slots' output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state' action slots' output m) b
 -> HalogenM state' action slots' output m b)
-> F (HalogenF state' action slots' output m) b
-> HalogenM state' action slots' output m b
forall a b. (a -> b) -> a -> b
$ HalogenF state' action slots' output m b
-> F (HalogenF state' action slots' output m) b
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state' action slots' output m b
 -> F (HalogenF state' action slots' output m) b)
-> HalogenF state' action slots' output m b
-> F (HalogenF state' action slots' output m) b
forall a b. (a -> b) -> a -> b
$ (UnliftIO (HalogenM state' action slots' output m) -> IO b)
-> HalogenF state' action slots' output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a.
(UnliftIO (HalogenM state action slots output m) -> IO a)
-> HalogenF state action slots output m a
Unlift ((UnliftIO (HalogenM state' action slots' output m) -> IO b)
 -> HalogenF state' action slots' output m b)
-> (UnliftIO (HalogenM state' action slots' output m) -> IO b)
-> HalogenF state' action slots' output m b
forall a b. (a -> b) -> a -> b
$ \(UnliftIO forall a. HalogenM state' action slots' output m a -> IO a
q) -> (forall a. HalogenM state' action slots' output m a -> IO a)
-> IO b
inner HalogenM state' action slots' output m a -> IO a
forall a. HalogenM state' action slots' output m a -> IO a
q

type HalogenIO state action slots output a = HalogenM state action slots output IO a

newtype HalogenAp state action slots output m a
  = HalogenAp (Ap (HalogenM state action slots output m) a)
  deriving ((forall a b.
 (a -> b)
 -> HalogenAp state action slots output m a
 -> HalogenAp state action slots output m b)
-> (forall a b.
    a
    -> HalogenAp state action slots output m b
    -> HalogenAp state action slots output m a)
-> Functor (HalogenAp state action slots output m)
forall a b.
a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m a
forall a b.
(a -> b)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
(a -> b)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
(a -> b)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
fmap :: forall a b.
(a -> b)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
$c<$ :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m a
<$ :: forall a b.
a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m a
Functor, Functor (HalogenAp state action slots output m)
Functor (HalogenAp state action slots output m) =>
(forall a. a -> HalogenAp state action slots output m a)
-> (forall a b.
    HalogenAp state action slots output m (a -> b)
    -> HalogenAp state action slots output m a
    -> HalogenAp state action slots output m b)
-> (forall a b c.
    (a -> b -> c)
    -> HalogenAp state action slots output m a
    -> HalogenAp state action slots output m b
    -> HalogenAp state action slots output m c)
-> (forall a b.
    HalogenAp state action slots output m a
    -> HalogenAp state action slots output m b
    -> HalogenAp state action slots output m b)
-> (forall a b.
    HalogenAp state action slots output m a
    -> HalogenAp state action slots output m b
    -> HalogenAp state action slots output m a)
-> Applicative (HalogenAp state action slots output m)
forall a. a -> HalogenAp state action slots output m a
forall a b.
HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m a
forall a b.
HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m b
forall a b.
HalogenAp state action slots output m (a -> b)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
forall a b c.
(a -> b -> c)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m c
forall state action (slots :: Row (*)) output (m :: * -> *).
Functor (HalogenAp state action slots output m)
forall state action (slots :: Row (*)) output (m :: * -> *) a.
a -> HalogenAp state action slots output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenAp state action slots output m (a -> b)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
forall state action (slots :: Row (*)) output (m :: * -> *) a b c.
(a -> b -> c)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall state action (slots :: Row (*)) output (m :: * -> *) a.
a -> HalogenAp state action slots output m a
pure :: forall a. a -> HalogenAp state action slots output m a
$c<*> :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenAp state action slots output m (a -> b)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
<*> :: forall a b.
HalogenAp state action slots output m (a -> b)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
$cliftA2 :: forall state action (slots :: Row (*)) output (m :: * -> *) a b c.
(a -> b -> c)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m c
liftA2 :: forall a b c.
(a -> b -> c)
-> HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m c
$c*> :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m b
*> :: forall a b.
HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m b
$c<* :: forall state action (slots :: Row (*)) output (m :: * -> *) a b.
HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m a
<* :: forall a b.
HalogenAp state action slots output m a
-> HalogenAp state action slots output m b
-> HalogenAp state action slots output m a
Applicative)

instance (Functor m) => MonadState state' (HalogenM state' action slots' output m) where
  state :: forall a.
(state' -> (a, state')) -> HalogenM state' action slots' output m a
state = F (HalogenF state' action slots' output m) a
-> HalogenM state' action slots' output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state' action slots' output m) a
 -> HalogenM state' action slots' output m a)
-> ((state' -> (a, state'))
    -> F (HalogenF state' action slots' output m) a)
-> (state' -> (a, state'))
-> HalogenM state' action slots' output m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HalogenF state' action slots' output m a
-> F (HalogenF state' action slots' output m) a
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state' action slots' output m a
 -> F (HalogenF state' action slots' output m) a)
-> ((state' -> (a, state'))
    -> HalogenF state' action slots' output m a)
-> (state' -> (a, state'))
-> F (HalogenF state' action slots' output m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (state' -> (a, state')) -> HalogenF state' action slots' output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
(state -> (a, state)) -> HalogenF state action slots output m a
State

instance (Functor m) => MonadParallel (HalogenM state' action slots' output m) where
  type Parallel (HalogenM state' action slots' output m) = HalogenAp state' action slots' output m
  parallel :: forall a.
HalogenM state' action slots' output m a
-> Parallel (HalogenM state' action slots' output m) a
parallel = Ap (HalogenM state' action slots' output m) a
-> HalogenAp state' action slots' output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
Ap (HalogenM state action slots output m) a
-> HalogenAp state action slots output m a
HalogenAp (Ap (HalogenM state' action slots' output m) a
 -> HalogenAp state' action slots' output m a)
-> (HalogenM state' action slots' output m a
    -> Ap (HalogenM state' action slots' output m) a)
-> HalogenM state' action slots' output m a
-> HalogenAp state' action slots' output m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HalogenM state' action slots' output m a
-> Ap (HalogenM state' action slots' output m) a
forall (f :: * -> *) a. f a -> Ap f a
liftAp
  sequential :: forall a.
Parallel (HalogenM state' action slots' output m) a
-> HalogenM state' action slots' output m a
sequential = F (HalogenF state' action slots' output m) a
-> HalogenM state' action slots' output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state' action slots' output m) a
 -> HalogenM state' action slots' output m a)
-> (HalogenAp state' action slots' output m a
    -> F (HalogenF state' action slots' output m) a)
-> HalogenAp state' action slots' output m a
-> HalogenM state' action slots' output m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HalogenF state' action slots' output m a
-> F (HalogenF state' action slots' output m) a
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state' action slots' output m a
 -> F (HalogenF state' action slots' output m) a)
-> (HalogenAp state' action slots' output m a
    -> HalogenF state' action slots' output m a)
-> HalogenAp state' action slots' output m a
-> F (HalogenF state' action slots' output m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HalogenAp state' action slots' output m a
-> HalogenF state' action slots' output m a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
HalogenAp state action slots output m a
-> HalogenF state action slots output m a
Par

-- | Raises an output message for the component.
raise :: forall state action slots output m. (Functor m) => output -> HalogenM state action slots output m ()
raise :: forall state action (slots :: Row (*)) output (m :: * -> *).
Functor m =>
output -> HalogenM state action slots output m ()
raise output
o = F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state action slots output m) ()
 -> HalogenM state action slots output m ())
-> F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state action slots output m ()
 -> F (HalogenF state action slots output m) ())
-> HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall a b. (a -> b) -> a -> b
$ output -> () -> HalogenF state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
output -> a -> HalogenF state action slots output m a
Raise output
o ()

-- | Sends a query to a child of a component at the specified slot.
query
  :: forall label
    ->forall state action output m slots query output' slot a
   . (HasType label (Slot query output' slot) slots)
  => (KnownSymbol label)
  => (Ord slot)
  => (Functor m)
  => slot
  -> query a
  -> HalogenM state action slots output m (Maybe a)
query :: forall (label :: Symbol) ->
forall state action output (m :: * -> *) (slots :: Row (*))
       (query :: * -> *) output' slot a.
(HasType label (Slot query output' slot) slots, KnownSymbol label,
 Ord slot, Functor m) =>
slot -> query a -> HalogenM state action slots output m (Maybe a)
query label slot
p query a
q =
  F (HalogenF state action slots output m) (Maybe a)
-> HalogenM state action slots output m (Maybe a)
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM
    (F (HalogenF state action slots output m) (Maybe a)
 -> HalogenM state action slots output m (Maybe a))
-> F (HalogenF state action slots output m) (Maybe a)
-> HalogenM state action slots output m (Maybe a)
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m (Maybe a)
-> F (HalogenF state action slots output m) (Maybe a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF
    (HalogenF state action slots output m (Maybe a)
 -> F (HalogenF state action slots output m) (Maybe a))
-> HalogenF state action slots output m (Maybe a)
-> F (HalogenF state action slots output m) (Maybe a)
forall a b. (a -> b) -> a -> b
$ ChildQuery slots (Maybe a)
-> HalogenF state action slots output m (Maybe a)
forall state action (slots :: Row (*)) output (m :: * -> *) a.
ChildQuery slots a -> HalogenF state action slots output m a
ChildQuery
    (ChildQuery slots (Maybe a)
 -> HalogenF state action slots output m (Maybe a))
-> ChildQuery slots (Maybe a)
-> HalogenF state action slots output m (Maybe a)
forall a b. (a -> b) -> a -> b
$ (forall (slot :: (* -> *) -> * -> *) (m :: * -> *).
 Applicative m =>
 (slot query output' -> m (Maybe a))
 -> SlotStorage slots slot -> m (Maybe a))
-> query a -> (Maybe a -> Maybe a) -> ChildQuery slots (Maybe a)
forall (g :: * -> *) o b (ps :: Row (*)) (f :: * -> *) a.
(forall (slot :: (* -> *) -> * -> *) (m :: * -> *).
 Applicative m =>
 (slot g o -> m (Maybe b)) -> SlotStorage ps slot -> m (f b))
-> g b -> (f b -> a) -> ChildQuery ps a
CQ.ChildQuery (\slot query output' -> m (Maybe a)
k -> m (Maybe a)
-> (slot query output' -> m (Maybe a))
-> Maybe (slot query output')
-> m (Maybe a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe a -> m (Maybe a)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing) slot query output' -> m (Maybe a)
k (Maybe (slot query output') -> m (Maybe a))
-> (SlotStorage slots slot -> Maybe (slot query output'))
-> SlotStorage slots slot
-> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. slot -> SlotStorage slots slot -> Maybe (slot query output')
(HasType label (Slot query output' slot) slots, KnownSymbol label,
 Ord slot) =>
slot -> SlotStorage slots slot -> Maybe (slot query output')
forall (symb :: Symbol) ->
(HasType symb (Slot query output' slot) slots, KnownSymbol symb,
 Ord slot) =>
slot -> SlotStorage slots slot -> Maybe (slot query output')
forall (query :: * -> *) output s (slots' :: Row (*))
       (slot :: (* -> *) -> * -> *).
forall (symb :: Symbol) ->
(HasType symb (Slot query output s) slots', KnownSymbol symb,
 Ord s) =>
s -> SlotStorage slots' slot -> Maybe (slot query output)
Slot.lookup label slot
p) query a
q Maybe a -> Maybe a
forall a. a -> a
identity

-- | Sends a query to all children of a component at a given slot label.
queryAll
  :: forall label
    ->forall state action output m slots query output' slot a
   . (HasType label (Slot query output' slot) slots)
  => (KnownSymbol label)
  => (Ord slot)
  => (Functor m)
  => query a
  -> HalogenM state action slots output m (Map slot a)
queryAll :: forall (label :: Symbol) ->
forall state action output (m :: * -> *) (slots :: Row (*))
       (query :: * -> *) output' slot a.
(HasType label (Slot query output' slot) slots, KnownSymbol label,
 Ord slot, Functor m) =>
query a -> HalogenM state action slots output m (Map slot a)
queryAll label query a
q =
  F (HalogenF state action slots output m) (Map slot a)
-> HalogenM state action slots output m (Map slot a)
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM
    (F (HalogenF state action slots output m) (Map slot a)
 -> HalogenM state action slots output m (Map slot a))
-> F (HalogenF state action slots output m) (Map slot a)
-> HalogenM state action slots output m (Map slot a)
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m (Map slot a)
-> F (HalogenF state action slots output m) (Map slot a)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF
    (HalogenF state action slots output m (Map slot a)
 -> F (HalogenF state action slots output m) (Map slot a))
-> HalogenF state action slots output m (Map slot a)
-> F (HalogenF state action slots output m) (Map slot a)
forall a b. (a -> b) -> a -> b
$ ChildQuery slots (Map slot a)
-> HalogenF state action slots output m (Map slot a)
forall state action (slots :: Row (*)) output (m :: * -> *) a.
ChildQuery slots a -> HalogenF state action slots output m a
ChildQuery
    (ChildQuery slots (Map slot a)
 -> HalogenF state action slots output m (Map slot a))
-> ChildQuery slots (Map slot a)
-> HalogenF state action slots output m (Map slot a)
forall a b. (a -> b) -> a -> b
$ (forall (slot :: (* -> *) -> * -> *) (m :: * -> *).
 Applicative m =>
 (slot query output' -> m (Maybe a))
 -> SlotStorage slots slot -> m (Map slot a))
-> query a
-> (Map slot a -> Map slot a)
-> ChildQuery slots (Map slot a)
forall (g :: * -> *) o b (ps :: Row (*)) (f :: * -> *) a.
(forall (slot :: (* -> *) -> * -> *) (m :: * -> *).
 Applicative m =>
 (slot g o -> m (Maybe b)) -> SlotStorage ps slot -> m (f b))
-> g b -> (f b -> a) -> ChildQuery ps a
CQ.ChildQuery (\slot query output' -> m (Maybe a)
k -> (Map slot (Maybe a) -> Map slot a)
-> m (Map slot (Maybe a)) -> m (Map slot a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map Map slot (Maybe a) -> Map slot a
forall k v. Ord k => Map k (Maybe v) -> Map k v
catMapMaybes (m (Map slot (Maybe a)) -> m (Map slot a))
-> (SlotStorage slots slot -> m (Map slot (Maybe a)))
-> SlotStorage slots slot
-> m (Map slot a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (slot query output' -> m (Maybe a))
-> Map slot (slot query output') -> m (Map slot (Maybe a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Map slot a -> f (Map slot b)
traverse slot query output' -> m (Maybe a)
k (Map slot (slot query output') -> m (Map slot (Maybe a)))
-> (SlotStorage slots slot -> Map slot (slot query output'))
-> SlotStorage slots slot
-> m (Map slot (Maybe a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Slot.slots label) query a
q Map slot a -> Map slot a
forall a. a -> a
identity
  where
    catMapMaybes :: forall k v. (Ord k) => Map k (Maybe v) -> Map k v
    catMapMaybes :: forall k v. Ord k => Map k (Maybe v) -> Map k v
catMapMaybes = (Map k v -> k -> Maybe v -> Map k v)
-> Map k v -> Map k (Maybe v) -> Map k v
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
M.foldlWithKey' (\Map k v
acc k
k Maybe v
v -> Map k v -> (v -> Map k v) -> Maybe v -> Map k v
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Map k v
acc ((v -> Map k v -> Map k v) -> Map k v -> v -> Map k v
forall a b c. (a -> b -> c) -> b -> a -> c
flip (k -> v -> Map k v -> Map k v
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert k
k) Map k v
acc) Maybe v
v) Map k v
forall k a. Map k a
M.empty

-- | 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.
subscribe :: forall state action slots output m. (Functor m) => HS.Emitter IO action -> HalogenM state action slots output m SubscriptionId
subscribe :: forall state action (slots :: Row (*)) output (m :: * -> *).
Functor m =>
Emitter IO action
-> HalogenM state action slots output m SubscriptionId
subscribe Emitter IO action
es = F (HalogenF state action slots output m) SubscriptionId
-> HalogenM state action slots output m SubscriptionId
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state action slots output m) SubscriptionId
 -> HalogenM state action slots output m SubscriptionId)
-> F (HalogenF state action slots output m) SubscriptionId
-> HalogenM state action slots output m SubscriptionId
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m SubscriptionId
-> F (HalogenF state action slots output m) SubscriptionId
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state action slots output m SubscriptionId
 -> F (HalogenF state action slots output m) SubscriptionId)
-> HalogenF state action slots output m SubscriptionId
-> F (HalogenF state action slots output m) SubscriptionId
forall a b. (a -> b) -> a -> b
$ (SubscriptionId -> Emitter IO action)
-> (SubscriptionId -> SubscriptionId)
-> HalogenF state action slots output m SubscriptionId
forall state action (slots :: Row (*)) output (m :: * -> *) a.
(SubscriptionId -> Emitter IO action)
-> (SubscriptionId -> a) -> HalogenF state action slots output m a
Subscribe (Emitter IO action -> SubscriptionId -> Emitter IO action
forall a b. a -> b -> a
const Emitter IO action
es) SubscriptionId -> SubscriptionId
forall a. a -> a
identity

-- | 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' :: forall state action slots output m. (Functor m) => (SubscriptionId -> HS.Emitter IO action) -> HalogenM state action slots output m ()
subscribe' :: forall state action (slots :: Row (*)) output (m :: * -> *).
Functor m =>
(SubscriptionId -> Emitter IO action)
-> HalogenM state action slots output m ()
subscribe' SubscriptionId -> Emitter IO action
esc = F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state action slots output m) ()
 -> HalogenM state action slots output m ())
-> F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state action slots output m ()
 -> F (HalogenF state action slots output m) ())
-> HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall a b. (a -> b) -> a -> b
$ (SubscriptionId -> Emitter IO action)
-> (SubscriptionId -> ())
-> HalogenF state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
(SubscriptionId -> Emitter IO action)
-> (SubscriptionId -> a) -> HalogenF state action slots output m a
Subscribe SubscriptionId -> Emitter IO action
esc (() -> SubscriptionId -> ()
forall a b. a -> b -> a
const ())

-- | Unsubscribes a component from a subscription. If the subscription associated
-- | with the ID has already ended this will have no effect.
unsubscribe :: forall state action slots output m. (Functor m) => SubscriptionId -> HalogenM state action slots output m ()
unsubscribe :: forall state action (slots :: Row (*)) output (m :: * -> *).
Functor m =>
SubscriptionId -> HalogenM state action slots output m ()
unsubscribe SubscriptionId
sid = F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state action slots output m) ()
 -> HalogenM state action slots output m ())
-> F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state action slots output m ()
 -> F (HalogenF state action slots output m) ())
-> HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall a b. (a -> b) -> a -> b
$ SubscriptionId -> () -> HalogenF state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
SubscriptionId -> a -> HalogenF state action slots output m a
Unsubscribe SubscriptionId
sid ()

-- | 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.
fork :: forall state action slots output m. (Functor m) => HalogenM state action slots output m () -> HalogenM state action slots output m ForkId
fork :: forall state action (slots :: Row (*)) output (m :: * -> *).
Functor m =>
HalogenM state action slots output m ()
-> HalogenM state action slots output m ForkId
fork HalogenM state action slots output m ()
hmu = F (HalogenF state action slots output m) ForkId
-> HalogenM state action slots output m ForkId
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state action slots output m) ForkId
 -> HalogenM state action slots output m ForkId)
-> F (HalogenF state action slots output m) ForkId
-> HalogenM state action slots output m ForkId
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m ForkId
-> F (HalogenF state action slots output m) ForkId
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state action slots output m ForkId
 -> F (HalogenF state action slots output m) ForkId)
-> HalogenF state action slots output m ForkId
-> F (HalogenF state action slots output m) ForkId
forall a b. (a -> b) -> a -> b
$ HalogenM state action slots output m ()
-> (ForkId -> ForkId)
-> HalogenF state action slots output m ForkId
forall state action (slots :: Row (*)) output (m :: * -> *) a.
HalogenM state action slots output m ()
-> (ForkId -> a) -> HalogenF state action slots output m a
Fork HalogenM state action slots output m ()
hmu ForkId -> ForkId
forall a. a -> a
identity

-- | 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.
join :: forall state action slots output m. (Functor m) => ForkId -> HalogenM state action slots output m ()
join :: forall state action (slots :: Row (*)) output (m :: * -> *).
Functor m =>
ForkId -> HalogenM state action slots output m ()
join ForkId
fid = F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state action slots output m) ()
 -> HalogenM state action slots output m ())
-> F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state action slots output m ()
 -> F (HalogenF state action slots output m) ())
-> HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall a b. (a -> b) -> a -> b
$ ForkId -> () -> HalogenF state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
ForkId -> a -> HalogenF state action slots output m a
Join ForkId
fid ()

-- | Kills a forked process if it is still running. Attempting to kill a forked
-- | process that has already ended will have no effect.
kill :: forall state action slots output m. (Functor m) => ForkId -> HalogenM state action slots output m ()
kill :: forall state action (slots :: Row (*)) output (m :: * -> *).
Functor m =>
ForkId -> HalogenM state action slots output m ()
kill ForkId
fid = F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state action slots output m) ()
 -> HalogenM state action slots output m ())
-> F (HalogenF state action slots output m) ()
-> HalogenM state action slots output m ()
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state action slots output m ()
 -> F (HalogenF state action slots output m) ())
-> HalogenF state action slots output m ()
-> F (HalogenF state action slots output m) ()
forall a b. (a -> b) -> a -> b
$ ForkId -> () -> HalogenF state action slots output m ()
forall state action (slots :: Row (*)) output (m :: * -> *) a.
ForkId -> a -> HalogenF state action slots output m a
Kill ForkId
fid ()

-- | Retrieves an `Element` value that is associated with a `Ref` in the
-- | rendered output of a component. If there is no currently rendered value for
-- | the requested ref this will return `Nothing`.
getRef :: forall state action slots output m. (Functor m) => RefLabel -> HalogenM state action slots output m (Maybe Element)
getRef :: forall state action (slots :: Row (*)) output (m :: * -> *).
Functor m =>
RefLabel -> HalogenM state action slots output m (Maybe Element)
getRef RefLabel
p = F (HalogenF state action slots output m) (Maybe Element)
-> HalogenM state action slots output m (Maybe Element)
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM (F (HalogenF state action slots output m) (Maybe Element)
 -> HalogenM state action slots output m (Maybe Element))
-> F (HalogenF state action slots output m) (Maybe Element)
-> HalogenM state action slots output m (Maybe Element)
forall a b. (a -> b) -> a -> b
$ HalogenF state action slots output m (Maybe Element)
-> F (HalogenF state action slots output m) (Maybe Element)
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (HalogenF state action slots output m (Maybe Element)
 -> F (HalogenF state action slots output m) (Maybe Element))
-> HalogenF state action slots output m (Maybe Element)
-> F (HalogenF state action slots output m) (Maybe Element)
forall a b. (a -> b) -> a -> b
$ RefLabel
-> (Maybe Element -> Maybe Element)
-> HalogenF state action slots output m (Maybe Element)
forall state action (slots :: Row (*)) output (m :: * -> *) a.
RefLabel
-> (Maybe Element -> a) -> HalogenF state action slots output m a
GetRef RefLabel
p Maybe Element -> Maybe Element
forall a. a -> a
identity

imapState
  :: forall state state' action slots output m a
   . (state -> state')
  -> (state' -> state)
  -> HalogenM state action slots output m a
  -> HalogenM state' action slots output m a
imapState :: forall state state' action (slots :: Row (*)) output (m :: * -> *)
       a.
(state -> state')
-> (state' -> state)
-> HalogenM state action slots output m a
-> HalogenM state' action slots output m a
imapState state -> state'
f state' -> state
f' = (state' -> (state, state -> state'))
-> HalogenM state action slots output m a
-> HalogenM state' action slots output m a
forall state state' action (slots :: Row (*)) output (m :: * -> *)
       a.
(state' -> (state, state -> state'))
-> HalogenM state action slots output m a
-> HalogenM state' action slots output m a
mapState (\state'
s' -> (state' -> state
f' state'
s', state -> state'
f))

mapState
  :: forall state state' action slots output m a
   . (state' -> (state, state -> state'))
  -> HalogenM state action slots output m a
  -> HalogenM state' action slots output m a
mapState :: forall state state' action (slots :: Row (*)) output (m :: * -> *)
       a.
(state' -> (state, state -> state'))
-> HalogenM state action slots output m a
-> HalogenM state' action slots output m a
mapState state' -> (state, state -> state')
lens = (state' -> (state, state -> state'))
-> (action -> action)
-> (output -> output)
-> (m ~> m)
-> HalogenM state action slots output m a
-> HalogenM state' action slots output m a
forall state state' action action' (slots :: Row (*)) output
       output' (m :: * -> *) (m' :: * -> *) a.
(state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state' action' slots output' m' a
mapHalogen state' -> (state, state -> state')
lens action -> action
forall a. a -> a
identity output -> output
forall a. a -> a
identity ((forall a. m a -> m a) -> m ~> m
forall {k} (m :: k -> *) (n :: k -> *).
(forall (a :: k). m a -> n a) -> m ~> n
NT m a -> m a
forall a. a -> a
forall a. m a -> m a
identity)

mapAction
  :: forall state action action' slots output m a
   . (Functor m)
  => (action -> action')
  -> HalogenM state action slots output m a
  -> HalogenM state action' slots output m a
mapAction :: forall state action action' (slots :: Row (*)) output (m :: * -> *)
       a.
Functor m =>
(action -> action')
-> HalogenM state action slots output m a
-> HalogenM state action' slots output m a
mapAction action -> action'
f = (state -> (state, state -> state))
-> (action -> action')
-> (output -> output)
-> (m ~> m)
-> HalogenM state action slots output m a
-> HalogenM state action' slots output m a
forall state state' action action' (slots :: Row (*)) output
       output' (m :: * -> *) (m' :: * -> *) a.
(state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state' action' slots output' m' a
mapHalogen state -> (state, state -> state)
forall s. s -> (s, s -> s)
identityLens action -> action'
f output -> output
forall a. a -> a
identity ((forall a. m a -> m a) -> m ~> m
forall {k} (m :: k -> *) (n :: k -> *).
(forall (a :: k). m a -> n a) -> m ~> n
NT m a -> m a
forall a. a -> a
forall a. m a -> m a
identity)

mapOutput
  :: forall state action slots output output' m a
   . (output -> output')
  -> HalogenM state action slots output m a
  -> HalogenM state action slots output' m a
mapOutput :: forall state action (slots :: Row (*)) output output' (m :: * -> *)
       a.
(output -> output')
-> HalogenM state action slots output m a
-> HalogenM state action slots output' m a
mapOutput output -> output'
fo = (state -> (state, state -> state))
-> (action -> action)
-> (output -> output')
-> (m ~> m)
-> HalogenM state action slots output m a
-> HalogenM state action slots output' m a
forall state state' action action' (slots :: Row (*)) output
       output' (m :: * -> *) (m' :: * -> *) a.
(state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state' action' slots output' m' a
mapHalogen state -> (state, state -> state)
forall s. s -> (s, s -> s)
identityLens action -> action
forall a. a -> a
identity output -> output'
fo ((forall a. m a -> m a) -> m ~> m
forall {k} (m :: k -> *) (n :: k -> *).
(forall (a :: k). m a -> n a) -> m ~> n
NT m a -> m a
forall a. a -> a
forall a. m a -> m a
identity)

hoist
  :: forall state action slots output m m' a
   . (Functor m')
  => (m ~> m')
  -> HalogenM state action slots output m a
  -> HalogenM state action slots output m' a
hoist :: forall state action (slots :: Row (*)) output (m :: * -> *)
       (m' :: * -> *) a.
Functor m' =>
(m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state action slots output m' a
hoist = (state -> (state, state -> state))
-> (action -> action)
-> (output -> output)
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state action slots output m' a
forall state state' action action' (slots :: Row (*)) output
       output' (m :: * -> *) (m' :: * -> *) a.
(state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state' action' slots output' m' a
mapHalogen state -> (state, state -> state)
forall s. s -> (s, s -> s)
identityLens action -> action
forall a. a -> a
identity output -> output
forall a. a -> a
identity

mapHalogen
  :: forall state state' action action' slots output output' m m' a
   . (state' -> (state, state -> state'))
  -> (action -> action')
  -> (output -> output')
  -> (m ~> m')
  -> HalogenM state action slots output m a
  -> HalogenM state' action' slots output' m' a
mapHalogen :: forall state state' action action' (slots :: Row (*)) output
       output' (m :: * -> *) (m' :: * -> *) a.
(state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state' action' slots output' m' a
mapHalogen state' -> (state, state -> state')
lens action -> action'
fa output -> output'
fo m ~> m'
nat (HalogenM F (HalogenF state action slots output m) a
alg) = F (HalogenF state' action' slots output' m') a
-> HalogenM state' action' slots output' m' a
forall state action (slots :: Row (*)) output (m :: * -> *) a.
F (HalogenF state action slots output m) a
-> HalogenM state action slots output m a
HalogenM ((forall x.
 HalogenF state action slots output m x
 -> HalogenF state' action' slots output' m' x)
-> F (HalogenF state action slots output m) a
-> F (HalogenF state' action' slots output' m') a
forall (f :: * -> *) (g :: * -> *) a.
(forall x. f x -> g x) -> F f a -> F g a
hoistF HalogenF state action slots output m x
-> HalogenF state' action' slots output' m' x
forall x.
HalogenF state action slots output m x
-> HalogenF state' action' slots output' m' x
go F (HalogenF state action slots output m) a
alg)
  where
    go :: forall x. HalogenF state action slots output m x -> HalogenF state' action' slots output' m' x
    go :: forall x.
HalogenF state action slots output m x
-> HalogenF state' action' slots output' m' x
go = \case
      State state -> (x, state)
f -> (state' -> (x, state'))
-> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
(state -> (a, state)) -> HalogenF state action slots output m a
State (\state'
s' -> let (state
s, state -> state'
g) = state' -> (state, state -> state')
lens state'
s' in (state -> state') -> (x, state) -> (x, state')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map state -> state'
g (state -> (x, state)
f state
s))
      Subscribe SubscriptionId -> Emitter IO action
fes SubscriptionId -> x
k -> (SubscriptionId -> Emitter IO action')
-> (SubscriptionId -> x)
-> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
(SubscriptionId -> Emitter IO action)
-> (SubscriptionId -> a) -> HalogenF state action slots output m a
Subscribe ((action -> action') -> Emitter IO action -> Emitter IO action'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map action -> action'
fa (Emitter IO action -> Emitter IO action')
-> (SubscriptionId -> Emitter IO action)
-> SubscriptionId
-> Emitter IO action'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SubscriptionId -> Emitter IO action
fes) SubscriptionId -> x
k
      Unsubscribe SubscriptionId
sid x
a -> SubscriptionId -> x -> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
SubscriptionId -> a -> HalogenF state action slots output m a
Unsubscribe SubscriptionId
sid x
a
      Lift m x
q -> m' x -> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
m a -> HalogenF state action slots output m a
Lift ((m ~> m') -> m x -> m' x
forall {k} (m :: k -> *) (n :: k -> *) (a :: k).
(m ~> n) -> m a -> n a
runNT m ~> m'
nat m x
q)
      Unlift UnliftIO (HalogenM state action slots output m) -> IO x
q -> (UnliftIO (HalogenM state' action' slots output' m') -> IO x)
-> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
(UnliftIO (HalogenM state action slots output m) -> IO a)
-> HalogenF state action slots output m a
Unlift ((UnliftIO (HalogenM state' action' slots output' m') -> IO x)
 -> HalogenF state' action' slots output' m' x)
-> (UnliftIO (HalogenM state' action' slots output' m') -> IO x)
-> HalogenF state' action' slots output' m' x
forall a b. (a -> b) -> a -> b
$ UnliftIO (HalogenM state action slots output m) -> IO x
q (UnliftIO (HalogenM state action slots output m) -> IO x)
-> (UnliftIO (HalogenM state' action' slots output' m')
    -> UnliftIO (HalogenM state action slots output m))
-> UnliftIO (HalogenM state' action' slots output' m')
-> IO x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a.
 HalogenM state action slots output m a
 -> HalogenM state' action' slots output' m' a)
-> UnliftIO (HalogenM state' action' slots output' m')
-> UnliftIO (HalogenM state action slots output m)
forall (m :: * -> *) (n :: * -> *).
(forall a. m a -> n a) -> UnliftIO n -> UnliftIO m
mapUnliftIO ((state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state' action' slots output' m' a
forall state state' action action' (slots :: Row (*)) output
       output' (m :: * -> *) (m' :: * -> *) a.
(state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state' action' slots output' m' a
mapHalogen state' -> (state, state -> state')
lens action -> action'
fa output -> output'
fo m ~> m'
nat)
      ChildQuery ChildQuery slots x
cq -> ChildQuery slots x -> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
ChildQuery slots a -> HalogenF state action slots output m a
ChildQuery ChildQuery slots x
cq
      Raise output
o x
a -> output' -> x -> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
output -> a -> HalogenF state action slots output m a
Raise (output -> output'
fo output
o) x
a
      Par (HalogenAp Ap (HalogenM state action slots output m) x
p) -> HalogenAp state' action' slots output' m' x
-> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
HalogenAp state action slots output m a
-> HalogenF state action slots output m a
Par (Ap (HalogenM state' action' slots output' m') x
-> HalogenAp state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
Ap (HalogenM state action slots output m) a
-> HalogenAp state action slots output m a
HalogenAp (Ap (HalogenM state' action' slots output' m') x
 -> HalogenAp state' action' slots output' m' x)
-> Ap (HalogenM state' action' slots output' m') x
-> HalogenAp state' action' slots output' m' x
forall a b. (a -> b) -> a -> b
$ (forall a.
 HalogenM state action slots output m a
 -> HalogenM state' action' slots output' m' a)
-> Ap (HalogenM state action slots output m) x
-> Ap (HalogenM state' action' slots output' m') x
forall (f :: * -> *) (g :: * -> *) a.
(forall x. f x -> g x) -> Ap f a -> Ap g a
hoistAp ((state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m x
-> HalogenM state' action' slots output' m' x
forall state state' action action' (slots :: Row (*)) output
       output' (m :: * -> *) (m' :: * -> *) a.
(state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state' action' slots output' m' a
mapHalogen state' -> (state, state -> state')
lens action -> action'
fa output -> output'
fo m ~> m'
nat) Ap (HalogenM state action slots output m) x
p)
      Fork HalogenM state action slots output m ()
hmu ForkId -> x
k -> HalogenM state' action' slots output' m' ()
-> (ForkId -> x) -> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
HalogenM state action slots output m ()
-> (ForkId -> a) -> HalogenF state action slots output m a
Fork ((state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m ()
-> HalogenM state' action' slots output' m' ()
forall state state' action action' (slots :: Row (*)) output
       output' (m :: * -> *) (m' :: * -> *) a.
(state' -> (state, state -> state'))
-> (action -> action')
-> (output -> output')
-> (m ~> m')
-> HalogenM state action slots output m a
-> HalogenM state' action' slots output' m' a
mapHalogen state' -> (state, state -> state')
lens action -> action'
fa output -> output'
fo m ~> m'
nat HalogenM state action slots output m ()
hmu) ForkId -> x
k
      Join ForkId
fid x
a -> ForkId -> x -> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
ForkId -> a -> HalogenF state action slots output m a
Join ForkId
fid x
a
      Kill ForkId
fid x
a -> ForkId -> x -> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
ForkId -> a -> HalogenF state action slots output m a
Kill ForkId
fid x
a
      GetRef RefLabel
p Maybe Element -> x
k -> RefLabel
-> (Maybe Element -> x)
-> HalogenF state' action' slots output' m' x
forall state action (slots :: Row (*)) output (m :: * -> *) a.
RefLabel
-> (Maybe Element -> a) -> HalogenF state action slots output m a
GetRef RefLabel
p Maybe Element -> x
k

identityLens :: forall s. s -> (s, s -> s)
identityLens :: forall s. s -> (s, s -> s)
identityLens s
s = (s
s, s -> s
forall a. a -> a
identity)