module Glazier.React.Element
( ReactElement
, unsafeCoerceElement
, mkBranchElement
, mkLeafElement
, textElement
, mkCombinedElements
) where
import qualified GHCJS.Marshal.Pure as J
import qualified GHCJS.Types as J
import qualified JavaScript.Array as JA
import qualified JavaScript.Object as JO
import qualified JavaScript.Extras as JE
newtype ReactElement = ReactElement J.JSVal
instance J.IsJSVal ReactElement
instance J.PToJSVal ReactElement where
pToJSVal = J.jsval
instance JE.ToJS ReactElement
unsafeCoerceElement :: J.JSVal -> ReactElement
unsafeCoerceElement = ReactElement
mkBranchElement :: JE.JSVar -> [JE.Property] -> [ReactElement] -> IO ReactElement
mkBranchElement n props xs =
js_mkBranchElement n (JE.fromProperties props) (JA.fromList $ JE.toJS <$> xs)
mkLeafElement :: JE.JSVar -> [JE.Property] -> IO ReactElement
mkLeafElement n props =
js_mkLeafElement n (JE.fromProperties props)
textElement :: J.JSString -> ReactElement
textElement = js_textElement
mkCombinedElements :: [ReactElement] -> IO ReactElement
mkCombinedElements xs = js_mkCombinedElements (JA.fromList $ JE.toJS <$> xs)
#ifdef __GHCJS__
foreign import javascript unsafe
"$r = React.createElement($1, $2, $3);"
js_mkBranchElement :: JE.JSVar -> JO.Object -> JA.JSArray -> IO ReactElement
foreign import javascript unsafe
"$r = React.createElement($1, $2);"
js_mkLeafElement :: JE.JSVar -> JO.Object -> IO ReactElement
foreign import javascript unsafe
"$r = $1;"
js_textElement :: J.JSString -> ReactElement
foreign import javascript unsafe
"$r = hgr$mkCombinedElements($1);"
js_mkCombinedElements :: JA.JSArray -> IO ReactElement
#else
js_mkBranchElement :: JE.JSVar -> JO.Object -> JA.JSArray -> IO ReactElement
js_mkBranchElement _ _ _ = pure (ReactElement J.nullRef)
js_mkLeafElement :: JE.JSVar -> JO.Object -> IO ReactElement
js_mkLeafElement _ _ = pure (ReactElement J.nullRef)
js_textElement :: J.JSString -> ReactElement
js_textElement _ = ReactElement J.nullRef
js_mkCombinedElements :: JA.JSArray -> IO ReactElement
js_mkCombinedElements _ = pure (ReactElement J.nullRef)
#endif