Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions js/miso.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ function drill(c) {
return c.child.domRef;
}
}
function bts() {
return __BACKGROUND__;
}

// ts/miso/dom.ts
function diff(c, n, parent, context) {
Expand Down Expand Up @@ -1108,6 +1111,7 @@ var drawingContext = {

// ts/index.ts
globalThis["miso"] = {
bts,
hydrationContext,
eventContext,
drawingContext,
Expand Down
2 changes: 1 addition & 1 deletion js/miso.prod.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"homepage": "https://haskell-miso.org",
"devDependencies": {
"@happy-dom/global-registrator": "^17.5.6",
"@happy-dom/global-registrator": "latest",
"prettier": "3.5.3",
"@types/bun": "latest"
},
Expand Down
13 changes: 13 additions & 0 deletions src/Miso.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
{-# OPTIONS_GHC -Wno-duplicate-exports #-}
-----------------------------------------------------------------------------
Expand Down Expand Up @@ -201,5 +202,17 @@ withJS action = void $ do
#ifdef WASM
$(evalFile MISO_JS_PATH)
#endif
#ifdef GHCJS_NEW
FFI.consoleLog "withJS"
onBTS <- FFI.bts
if onBTS
then do
FFI.consoleLog "on bts"
void action
else do
FFI.consoleLog "on mts, bailing"
pure ()
#else
action
#endif
-----------------------------------------------------------------------------
2 changes: 2 additions & 0 deletions src/Miso/FFI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ module Miso.FFI
, splitmix32
-- ** Math.random()
, mathRandom
-- ** Native helpers
, bts
) where
-----------------------------------------------------------------------------
import Miso.FFI.Internal
Expand Down
10 changes: 7 additions & 3 deletions src/Miso/FFI/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ module Miso.FFI.Internal
, mathRandom
-- * Crypto
, getRandomValue
-- * Native
, bts
) where
-----------------------------------------------------------------------------
import Control.Monad (void, forM_, (<=<), when)
Expand Down Expand Up @@ -460,14 +462,13 @@ diff (Object a) (Object b) c = do
delegator :: JSVal -> JSVal -> Bool -> IO JSVal -> IO ()
delegator mountPoint events debug getVTree = do
ctx <- getEventContext
d <- toJSVal debug
#ifdef WASM
cb <- asyncCallback1 $ \continuation -> void (call continuation global =<< getVTree)
#else
cb <- syncCallback1 $ \continuation -> void (call continuation global =<< getVTree)
#endif
d <- toJSVal debug
moduleMiso <- jsg "miso"
void $ moduleMiso # "delegator" $ [mountPoint,events,cb,d,ctx]
void $ ctx # "delegator" $ [mountPoint,events,cb,d,ctx]
-----------------------------------------------------------------------------
-- | Copies DOM pointers into virtual dom entry point into isomorphic javascript
--
Expand Down Expand Up @@ -1037,3 +1038,6 @@ getRandomValue :: IO Double
getRandomValue = fromJSValUnchecked =<< do
jsg "miso" # "getRandomValues" $ ()
-----------------------------------------------------------------------------
bts :: IO Bool
bts = fromJSValUnchecked =<< do jsg "miso" # "bts" $ ()
-----------------------------------------------------------------------------
1 change: 1 addition & 0 deletions src/Miso/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ initialize events _componentParentId hydrate isRoot comp@Component {..} getCompo
Diff.diff (Just oldVTree) (Just newVTree) _componentDOMRef
FFI.updateRef oldVTree newVTree
liftIO (atomicWriteIORef _componentVTree newVTree)
FFI.flush

let _componentApplyActions = \(actions :: [action]) model_ comps -> do
let info = ComponentInfo _componentId _componentParentId _componentDOMRef
Expand Down
2 changes: 2 additions & 0 deletions ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getRandomValues,
splitmix32,
delegateEvent,
bts,
} from './miso';

import {
Expand All @@ -33,6 +34,7 @@ import {

/* export globally */
globalThis['miso'] = {
bts,
hydrationContext,
eventContext,
drawingContext,
Expand Down
2 changes: 2 additions & 0 deletions ts/miso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
updateRef,
inline,
typeOf,
bts,
mathRandom,
getRandomValues,
splitmix32,
Expand Down Expand Up @@ -109,6 +110,7 @@ export {
splitmix32,
delegateEvent,
getDOMRef,
bts,

/* Types */
VTree,
Expand Down
4 changes: 4 additions & 0 deletions ts/miso/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,7 @@ export function drill<T>(c: VComp<T>): T {
return c.child.domRef;
}
}

export function bts () : boolean {
return __BACKGROUND__;
}
Loading