Skip to content

Commit

Permalink
Merge pull request #471 from sgrb/fix-build
Browse files Browse the repository at this point in the history
Support building with ghc-9.8 js backend
  • Loading branch information
alexfmpe authored Nov 2, 2024
2 parents 307e6c2 + 4e06bcc commit 3ebba46
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
18 changes: 9 additions & 9 deletions reflex-dom-core/reflex-dom-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ library
aeson >= 0.8 && < 2.3,
base >= 4.7 && < 4.20,
bifunctors >= 4.2 && < 6,
bimap >= 0.3 && < 0.5,
bimap >= 0.3 && < 0.6,
blaze-builder >= 0.4.1 && < 0.5,
bytestring >= 0.10 && < 0.13,
case-insensitive < 1.3,
commutative-semigroups >=0.1 && <0.2,
commutative-semigroups >=0.1 && <0.3,
containers >= 0.6 && < 0.7,
constraints >= 0.9 && < 0.14,
constraints >= 0.9 && < 0.15,
contravariant >= 1.4 && < 1.6,
data-default >= 0.5 && < 0.8,
dependent-map >= 0.3 && < 0.5,
Expand All @@ -95,18 +95,18 @@ library
random >= 1.1 && < 1.3,
ref-tf >= 0.4 && < 0.6,
reflex >= 0.8.2.1 && < 1,
semigroups >= 0.16 && < 0.20,
semigroups >= 0.16 && < 0.21,
stm >= 2.4 && < 2.6,
text == 1.2.*,
text >= 1.2 && < 2.1,
transformers >= 0.3 && < 0.7,
network-uri >= 2.6.1 && < 2.7,
zenc == 0.1.*

if impl(ghcjs)
if impl(ghcjs) || arch(javascript)
hs-source-dirs: src-ghcjs
build-depends:
ghcjs-base,
hashable >= 1.2 && < 1.4
hashable >= 1.2 && < 1.5
else
hs-source-dirs: src-ghc
if !os(windows)
Expand All @@ -118,7 +118,7 @@ library
these >= 1 && < 1.3
else
build-depends:
these >= 0.4 && < 0.9
these >= 0.4 && < 1.0

exposed-modules:
Foreign.JavaScript.TH
Expand Down Expand Up @@ -170,7 +170,7 @@ library
if flag(use-template-haskell)
build-depends:
dependent-sum-template >= 0.1 && < 0.3,
template-haskell >= 2.12.0 && < 2.22
template-haskell >= 2.12.0 && < 2.23
other-extensions: TemplateHaskell
cpp-options: -DUSE_TEMPLATE_HASKELL
other-modules:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE JavaScriptFFI #-}

Expand All @@ -9,7 +10,11 @@ module Foreign.JavaScript.Internal.Utils

import GHCJS.Concurrent
import GHCJS.DOM.Types (JSM, JSVal, RequestAnimationFrameCallback (..))
#ifdef __GHCJS__
import GHCJS.Foreign.Callback (releaseCallback)
#else
import GHC.JS.Foreign.Callback (releaseCallback)
#endif

freeRequestAnimationFrameCallback :: RequestAnimationFrameCallback -> JSM ()
freeRequestAnimationFrameCallback (RequestAnimationFrameCallback cb) = releaseCallback cb
Expand Down
4 changes: 4 additions & 0 deletions reflex-dom-core/src/Foreign/JavaScript/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ import qualified GHCJS.Buffer as JS
import GHCJS.DOM.Types (MonadJSM)
import qualified GHCJS.DOM.Types as JS
import qualified GHCJS.Foreign as JS
#ifdef __GHCJS__
import qualified GHCJS.Foreign.Callback as JS
import qualified GHCJS.Foreign.Callback.Internal (Callback (..))
#else
import qualified GHC.JS.Foreign.Callback as JS
#endif
import qualified JavaScript.Array as JS
import qualified JavaScript.Array.Internal (SomeJSArray (..))
import qualified JavaScript.Object as JS
Expand Down
18 changes: 9 additions & 9 deletions reflex-dom-core/src/Reflex/Dom/Builder/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,6 @@ elementConfig_eventSpec f (ElementConfig a b c d) = (\d' -> ElementConfig a b c
{-# INLINE elementConfig_eventSpec #-}
#endif

instance (Reflex t, er ~ EventResult, DomSpace s) => Default (ElementConfig er t s) where
{-# INLINABLE def #-}
def = ElementConfig
{ _elementConfig_namespace = Nothing
, _elementConfig_initialAttributes = mempty
, _elementConfig_modifyAttributes = Nothing
, _elementConfig_eventSpec = def
}

data Element er d t
= Element { _element_events :: EventSelector t (WrapArg er EventName) --TODO: EventSelector should have two arguments
, _element_raw :: RawElement d
Expand Down Expand Up @@ -317,6 +308,15 @@ inputElementConfig_elementConfig f (InputElementConfig a b c d e) = (\e' -> Inpu
{-# INLINE inputElementConfig_elementConfig #-}
#endif

instance (Reflex t, er ~ EventResult, DomSpace s) => Default (ElementConfig er t s) where
{-# INLINABLE def #-}
def = ElementConfig
{ _elementConfig_namespace = Nothing
, _elementConfig_initialAttributes = mempty
, _elementConfig_modifyAttributes = Nothing
, _elementConfig_eventSpec = def
}

instance (Reflex t, er ~ EventResult, DomSpace s) => Default (InputElementConfig er t s) where
{-# INLINABLE def #-}
def = InputElementConfig
Expand Down
12 changes: 12 additions & 0 deletions reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,11 @@ removeSubsequentNodes :: (MonadJSM m, IsNode n) => n -> m ()
#ifdef ghcjs_HOST_OS
--NOTE: Although wrapping this javascript in a function seems unnecessary, GHCJS's optimizer will break it if it is entered without that wrapping (as of 2021-11-06)
foreign import javascript unsafe
#ifdef __GHCJS__
"(function() { var n = $1; while (n['nextSibling']) { n['parentNode']['removeChild'](n['nextSibling']); }; })()"
#else
"(function(n) { while (n['nextSibling']) { n['parentNode']['removeChild'](n['nextSibling']); }; })"
#endif
removeSubsequentNodes_ :: DOM.Node -> IO ()
removeSubsequentNodes n = liftJSM $ removeSubsequentNodes_ (toNode n)
#else
Expand All @@ -489,7 +493,11 @@ extractBetweenExclusive :: (MonadJSM m, IsNode start, IsNode end) => DOM.Documen
#ifdef ghcjs_HOST_OS
--NOTE: Although wrapping this javascript in a function seems unnecessary, GHCJS's optimizer will break it if it is entered without that wrapping (as of 2021-11-06)
foreign import javascript unsafe
#ifdef __GHCJS__
"(function() { var df = $1; var s = $2; var e = $3; var x; for(;;) { x = s['nextSibling']; if(e===x) { break; }; df['appendChild'](x); } })()"
#else
"(function(df, s, e) { var x; for(;;) { x = s['nextSibling']; if(e===x) { break; }; df['appendChild'](x); } })"
#endif
extractBetweenExclusive_ :: DOM.DocumentFragment -> DOM.Node -> DOM.Node -> IO ()
extractBetweenExclusive df s e = liftJSM $ extractBetweenExclusive_ df (toNode s) (toNode e)
#else
Expand All @@ -510,7 +518,11 @@ extractUpTo :: (MonadJSM m, IsNode start, IsNode end) => DOM.DocumentFragment ->
#ifdef ghcjs_HOST_OS
--NOTE: Although wrapping this javascript in a function seems unnecessary, GHCJS's optimizer will break it if it is entered without that wrapping (as of 2017-09-04)
foreign import javascript unsafe
#ifdef __GHCJS__
"(function() { var x = $2; while(x !== $3) { var y = x['nextSibling']; $1['appendChild'](x); x = y; } })()"
#else
"(function(_, x, $3) { while(x !== $3) { var y = x['nextSibling']; $1['appendChild'](x); x = y; } })"
#endif
extractUpTo_ :: DOM.DocumentFragment -> DOM.Node -> DOM.Node -> IO ()
extractUpTo df s e = liftJSM $ extractUpTo_ df (toNode s) (toNode e)
#else
Expand Down
2 changes: 1 addition & 1 deletion reflex-dom-core/src/Reflex/Dom/Builder/Static.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module Reflex.Dom.Builder.Static where
import Data.IORef (IORef)
import Blaze.ByteString.Builder.Html.Utf8
import Control.Lens hiding (element)
import Control.Monad.Exception
import Control.Monad
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Identity
import Control.Monad.Primitive
Expand Down

0 comments on commit 3ebba46

Please sign in to comment.