{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Miso.Diff
( diff
, mountElement
) where
import qualified Miso.FFI.Internal as FFI
import Miso.Types
import Miso.DSL
diff :: Maybe VTree -> Maybe VTree -> JSVal -> IO ()
diff :: Maybe VTree -> Maybe VTree -> JSVal -> IO ()
diff Maybe VTree
current Maybe VTree
new_ JSVal
mountEl =
case (Maybe VTree
current, Maybe VTree
new_) of
(Maybe VTree
Nothing, Maybe VTree
Nothing) -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
(Just (VTree Object
current'), Just (VTree Object
new')) -> do
Object -> Object -> JSVal -> IO ()
FFI.diff Object
current' Object
new' JSVal
mountEl
IO ()
FFI.flush
(Maybe VTree
Nothing, Just (VTree Object
new')) -> do
Object -> Object -> JSVal -> IO ()
FFI.diff (JSVal -> Object
Object JSVal
jsNull) Object
new' JSVal
mountEl
IO ()
FFI.flush
(Just (VTree Object
current'), Maybe VTree
Nothing) -> do
Object -> Object -> JSVal -> IO ()
FFI.diff Object
current' (JSVal -> Object
Object JSVal
jsNull) JSVal
mountEl
IO ()
FFI.flush
mountElement :: MisoString -> IO JSVal
mountElement :: MisoString -> IO JSVal
mountElement = \case
MisoString
"body" -> IO JSVal
FFI.getBody
MisoString
e -> MisoString -> IO JSVal
FFI.getElementById MisoString
e