Skip to content

Commit

Permalink
Expose global sink
Browse files Browse the repository at this point in the history
  • Loading branch information
dmjio committed Oct 31, 2024
1 parent 0305b26 commit 5187b97
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Miso.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ import Control.Monad
import Control.Monad.IO.Class
import Data.IORef
import Data.List
import Data.Sequence ((|>))
import Data.Sequence ((|>))
import qualified Data.Sequence as S
import qualified JavaScript.Object.Internal as OI
import System.IO.Unsafe
import System.Mem.StableName
import qualified Data.Sequence as S
import qualified JavaScript.Object.Internal as OI

#ifndef ghcjs_HOST_OS
import Language.Javascript.JSaddle (eval, waitForAnimationFrame)
import Language.Javascript.JSaddle (eval, waitForAnimationFrame)
#ifdef IOS
import Miso.JSBits
#else
import GHCJS.Types (JSString)
import GHCJS.Types (JSString)
import Data.FileEmbed
#endif
#else
Expand Down Expand Up @@ -99,6 +100,8 @@ common App {..} m getView = do
let writeEvent a = void . liftIO . forkIO $ do
atomicModifyIORef' actionsRef $ \as -> (as |> a, ())
notify
-- init global sink
liftIO (writeIORef globalSinkRef writeEvent)
-- init Subs
forM_ subs $ \sub ->
sub writeEvent
Expand Down Expand Up @@ -152,6 +155,13 @@ miso f = do
-- Create virtual dom, perform initial diff
liftIO (newIORef initialVTree)

globalSinkRef :: IORef (Sink action)
{-# NOINLINE globalSinkRef #-}
globalSinkRef = unsafePerformIO $ newIORef (\_ -> pure ())

globalSink :: IO (Sink action)
globalSink = readIORef globalSinkRef

-- | Runs a miso application
startApp :: Eq model => App model action -> JSM ()
startApp app@App {..} =
Expand Down

0 comments on commit 5187b97

Please sign in to comment.