module Data.DOM.WBTypes (
castExpr
,exprType
,(/\)
,setjsProperty
) where
import WebBits.JavaScript
import qualified Data.Foldable as F
import Control.Monad
castExpr :: b -> Expression a -> Expression b
castExpr b e = fmap (const b) e
exprType :: Expression a -> a
exprType e =
let f y z = NullLit (undefined :: a)
(NullLit x) = F.foldr f undefined e
in x
(/\) :: Expression a -> b -> Expression b
(/\) = flip castExpr
setjsProperty :: (Monad m) => String -> Expression a -> Expression this -> m (Expression this)
setjsProperty pn pv this = do
let tht = exprType this
fun = FuncExpr tht [Id tht "x"] blk
thv = VarRef tht (Id tht "x")
blk = BlockStmt tht [setp, retx]
setp = ExprStmt tht $ AssignExpr tht OpAssign (DotRef tht thv (Id tht pn)) (pv /\ tht)
retx = ReturnStmt tht (Just thv)
return $ ParenExpr tht $ CallExpr tht fun [this]