{-# LANGUAGE CPP #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
module Miso
(
miso
, startApp
, sink
, sample
, notify
, module Miso.Types
, module Miso.Effect
, module Miso.Event
, module Miso.Html
, module Miso.Render
, module Miso.Mathml
, module Miso.Router
, module Miso.Run
, module Miso.Exception
, module Miso.Subscription
, module Miso.Storage
, module Miso.Util
, set
, now
, consoleLog
, consoleLog'
, consoleError
, consoleWarn
, getElementById
, focus
, blur
, alert
, reload
) where
import Control.Monad (void)
import Control.Monad.IO.Class (liftIO)
import Data.IORef (newIORef)
import Language.Javascript.JSaddle (Object(Object), JSM)
#ifndef GHCJS_BOTH
import Data.FileEmbed (embedStringFile)
import Language.Javascript.JSaddle (eval)
import Miso.String (MisoString)
#endif
import Miso.Diff (diff, mountElement)
import Miso.Effect
import Miso.Event
import Miso.Exception
import Miso.Html
import Miso.Render
import Miso.Router
import Miso.Run
import Miso.Mathml
import Miso.Subscription
import Miso.Types
import Miso.Util
import Miso.Storage
import Miso.Internal
import Miso.FFI hiding (diff)
miso :: Eq model => (URI -> App effect model action a) -> JSM ()
miso f = withJS $ do
app@App {..} <- f <$> getCurrentURI
initialize app $ \snk -> do
VTree (Object vtree) <- runView Prerender (view model) snk logLevel events
let name = getMountPoint mountPoint
setBodyComponent name
mount <- getBody
hydrate (logLevel `elem` [DebugPrerender, DebugAll]) mount vtree
viewRef <- liftIO $ newIORef $ VTree (Object vtree)
pure (name, mount, viewRef)
startApp :: Eq model => App effect model action a -> JSM ()
startApp app@App {..} = withJS $
initialize app $ \snk -> do
vtree <- runView DontPrerender (view model) snk logLevel events
let name = getMountPoint mountPoint
setBodyComponent name
mount <- mountElement name
diff mount Nothing (Just vtree)
viewRef <- liftIO (newIORef vtree)
pure (name, mount, viewRef)
withJS :: JSM a -> JSM ()
withJS action = void $ do
#ifndef GHCJS_BOTH
_ <- eval ($(embedStringFile "js/miso.js") :: MisoString)
#endif
action