{-# LANGUAGE DeriveFunctor #-}
module JMonkey.Action
(
JMonkey
, JMonkeyM
, Action(..)
, Cond(..)
, putLog
, alert
, select
, add
, adds
, remove
, removes
, on
, onClick
, onScroll
, onChange
, onTime
, ifel
, ifThen
, elThen
)
where
import Control.Monad.Free
import JMonkey.Data
type JMonkey = JMonkeyM ()
type JMonkeyM = Free Action
data Action n
= Log String n
| Alert String n
| Select Selector (Target -> n)
| Add Target Selector n
| Remove Target Selector n
| On String Target JMonkey n
| OnTime Repeat Int JMonkey n
| If Cond JMonkey JMonkey n
deriving Functor
data Cond
= Possess Target Selector
| YOffset CompOp Double
putLog :: String -> JMonkey
putLog s = liftF $ Log s ()
alert :: String -> JMonkey
alert s = liftF $ Alert s ()
select :: Selector -> JMonkeyM Target
select sel = liftF $ Select sel id
add :: Target -> Selector -> JMonkey
add t sel = liftF $ Add t sel ()
adds :: [Target] -> Selector -> JMonkey
adds ts sel = mapM_ (\t -> add t sel) ts
remove :: Target -> Selector -> JMonkey
remove t sel = liftF $ Remove t sel ()
removes :: [Target] -> Selector -> JMonkey
removes ts sel = mapM_ (\t -> remove t sel) ts
on
:: String
-> Target
-> JMonkey
-> JMonkey
on s t act = liftF $ On s t act ()
onClick :: Target -> JMonkey -> JMonkey
onClick t act = liftF $ On "click" t act ()
onScroll :: Target -> JMonkey -> JMonkey
onScroll t act = liftF $ On "scroll" t act ()
onChange :: Target -> JMonkey -> JMonkey
onChange t act = liftF $ On "change" t act ()
onTime
:: Repeat
-> Int
-> JMonkey
-> JMonkey
onTime r t act = liftF $ OnTime r t act ()
ifel
:: Cond
-> JMonkey
-> JMonkey
-> JMonkey
ifel c tA fA = liftF $ If c tA fA ()
ifThen :: Cond -> JMonkey -> JMonkey
ifThen c tA = ifel c tA noop
elThen :: Cond -> JMonkey -> JMonkey
elThen c = ifel c noop
noop :: JMonkey
noop = Pure ()