{-# LANGUAGE CPP #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -Wno-duplicate-exports #-}
module Miso
(
miso
, (🍜)
, App
, startApp
, renderApp
, Component
, component
, (+>)
, mount_
, withSink
, Sink
, mail
, checkMail
, parent
, mailParent
, broadcast
, startSub
, stopSub
, Sub
, issue
, batch
, io
, io_
, sync
, sync_
, for
#ifdef WASM
, evalFile
#endif
, module Miso.Binding
, module Miso.DSL
, module Miso.Effect
, module Miso.Event
, module Miso.Fetch
, module Miso.PubSub
, module Miso.Property
, module Miso.Reload
, module Miso.Subscription
, module Miso.Storage
, module Miso.Types
, module Miso.Util
, module Miso.FFI
, module Miso.State
) where
import Control.Monad (void)
import Miso.Binding
import Miso.Diff
import Miso.DSL
import Miso.Effect
import Miso.Event
import Miso.Fetch
import Miso.FFI
import qualified Miso.FFI.Internal as FFI
import Miso.Property
import Miso.PubSub
import Miso.Reload
import Miso.Router
import Miso.Runtime
import Miso.State
import Miso.Storage
import Miso.Subscription
import Miso.Types
import Miso.Util
miso :: Eq model => Events -> (URI -> App model action) -> IO ()
miso :: forall model action.
Eq model =>
Events -> (URI -> App model action) -> IO ()
miso Events
events URI -> App model action
f = IO (ComponentState ROOT model action) -> IO ()
forall a. IO a -> IO ()
withJS (IO (ComponentState ROOT model action) -> IO ())
-> IO (ComponentState ROOT model action) -> IO ()
forall a b. (a -> b) -> a -> b
$ do
vcomp <- URI -> App model action
f (URI -> App model action) -> IO URI -> IO (App model action)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO URI
getURI
body <- FFI.getBody
initialize events rootComponentId Hydrate isRoot vcomp (pure body)
startApp :: Eq model => Events -> App model action -> IO ()
startApp :: forall model action.
Eq model =>
Events -> App model action -> IO ()
startApp Events
events App model action
vcomp = IO (ComponentState ROOT model action) -> IO ()
forall a. IO a -> IO ()
withJS (Events -> App model action -> IO (ComponentState ROOT model action)
forall parent model action.
(Eq parent, Eq model) =>
Events
-> Component parent model action
-> IO (ComponentState parent model action)
initComponent Events
events App model action
vcomp)
(🍜) :: Eq model => Events -> (URI -> App model action) -> IO ()
🍜 :: forall model action.
Eq model =>
Events -> (URI -> App model action) -> IO ()
(🍜) = Events -> (URI -> App model action) -> IO ()
forall model action.
Eq model =>
Events -> (URI -> App model action) -> IO ()
miso
renderApp
:: Eq model
=> Events
-> MisoString
-> App model action
-> IO ()
renderApp :: forall model action.
Eq model =>
Events -> MisoString -> App model action -> IO ()
renderApp Events
events MisoString
renderer App model action
vcomp =
IO (ComponentState ROOT model action) -> IO ()
forall a. IO a -> IO ()
withJS (MisoString -> IO ()
FFI.setDrawingContext MisoString
renderer IO ()
-> IO (ComponentState ROOT model action)
-> IO (ComponentState ROOT model action)
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Events -> App model action -> IO (ComponentState ROOT model action)
forall parent model action.
(Eq parent, Eq model) =>
Events
-> Component parent model action
-> IO (ComponentState parent model action)
initComponent Events
events App model action
vcomp)
initComponent
:: (Eq parent, Eq model)
=> Events
-> Component parent model action
-> IO (ComponentState parent model action)
initComponent :: forall parent model action.
(Eq parent, Eq model) =>
Events
-> Component parent model action
-> IO (ComponentState parent model action)
initComponent Events
events vcomp :: Component parent model action
vcomp@Component {model
Bool
[Binding parent model]
[JS]
[CSS]
[Sub action]
Maybe action
Maybe (IO model)
Maybe MisoString
LogLevel
model -> View model action
action -> Effect parent model action
Value -> Maybe action
model :: model
hydrateModel :: Maybe (IO model)
update :: action -> Effect parent model action
view :: model -> View model action
subs :: [Sub action]
styles :: [CSS]
scripts :: [JS]
mountPoint :: Maybe MisoString
logLevel :: LogLevel
mailbox :: Value -> Maybe action
bindings :: [Binding parent model]
eventPropagation :: Bool
mount :: Maybe action
unmount :: Maybe action
unmount :: forall parent model action.
Component parent model action -> Maybe action
mount :: forall parent model action.
Component parent model action -> Maybe action
eventPropagation :: forall parent model action. Component parent model action -> Bool
bindings :: forall parent model action.
Component parent model action -> [Binding parent model]
mailbox :: forall parent model action.
Component parent model action -> Value -> Maybe action
logLevel :: forall parent model action.
Component parent model action -> LogLevel
mountPoint :: forall parent model action.
Component parent model action -> Maybe MisoString
scripts :: forall parent model action. Component parent model action -> [JS]
styles :: forall parent model action. Component parent model action -> [CSS]
subs :: forall parent model action.
Component parent model action -> [Sub action]
view :: forall parent model action.
Component parent model action -> model -> View model action
update :: forall parent model action.
Component parent model action
-> action -> Effect parent model action
hydrateModel :: forall parent model action.
Component parent model action -> Maybe (IO model)
model :: forall parent model action. Component parent model action -> model
..} = do
root <- MisoString -> IO JSVal
mountElement (Maybe MisoString -> MisoString
getMountPoint Maybe MisoString
mountPoint)
initialize events rootComponentId Draw isRoot vcomp (pure root)
isRoot :: Bool
isRoot :: Bool
isRoot = Bool
True
#ifdef PRODUCTION
#define MISO_JS_PATH "js/miso.prod.js"
#else
#define MISO_JS_PATH "js/miso.js"
#endif
withJS :: IO a -> IO ()
withJS :: forall a. IO a -> IO ()
withJS IO a
action = IO a -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO a -> IO ()) -> IO a -> IO ()
forall a b. (a -> b) -> a -> b
$ do
#ifdef WASM
$(evalFile MISO_JS_PATH)
#endif
action