-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make examples runnable with jsaddle-warp
#23
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is largely adapted from Miso's own examples. I don't know whether there's any particular reason this hadn't already been done in this repository. Maybe just that GHC's WASM backend is nowhere near as slow as GHCJS, so it's a bit less important? Anyway, I thought I may as well see whether you'd be interested in upstreaming this before going any further.
Definitely interested, we even had jsaddle-warp support in this repo in the past, but removed it because it caused churn (see #6 (review)). Also, the fact that the WASM backend is much faster than GHCJS definitely is a part of the somewhat reduced benefit.
However, recent social media posts like https://redd.it/1g2lanx show that not everyone not aware of this possibility (which in particular gives HLS support), so I think it would be quite nice to demo this in this repo, thanks for (re)starting that effort! Will take a look soon.
a4d49d1
to
14a29ad
Compare
All previous versions are broken, especially without Hackage revisions to add bounds: dmjio/miso#752.
d87886d
to
d482b06
Compare
This is probably worth rewriting from scratch on top of dmjio/miso#768 and ideally dmjio/miso#770. A lot of the comments in OP are outdated anyway, and the history has become a bit messy as I've experimented with things. |
Then again, given that Miso's own examples now build with Wasm since dmjio/miso#768, maybe it's time to think about retiring this whole repository... |
Allows running examples locally without targeting WASM, e.g. with
cabal run ghc-wasm-miso-examples -- snake
. Note that it doesn't work on Firefox: ghcjs/jsaddle#64.Code is largely adapted from Miso's own example. I don't know whether there's any particular reason this hadn't already been done in this repository. Maybe just that GHC's WASM backend is nowhere near as slow as GHCJS, so it's a bit less important? Anyway, I thought I may as well see whether you'd be interested in upstreaming this before going any further.
Note that a major reason for this is HLS support: haskell/haskell-language-server#4187.
There are still quite a few things that could be improved:
Main.hs
are completely separate, so perhaps we're better off using two separate modules and Cabal conditionals instead.App.hs
is a bit awkward, and potentially overly complicated, sinceData.JSString.Internal.Type.JSString
is not the same asGHC.Internal.Wasm.Prim.Types.JSString
. This is also the reason for the extra annotations in this file andXHR.hs
: monomorphising the former gives us some compatiblity. It's possible thatjsaddle
could be improved to abstract over this difference../build.sh
requires acabal clean
. Presumably more could be done to keep build folders separate.main
after Use TH-enabled build, remove custom miso #24.debug
) from the Miso examples for now. This is simpler and easier to understand, sincejsaddle-warp
has a pretty bad and under-documented API, but it does limit some of the main benefits.debugOr 8080 (f >> syncPoint) jsaddleApp
is. I've found that just usingdebug 8000 f
works fine.wai-app-static
, replacingjsaddleApp
with(jsaddleAppWithJsOr (jsaddleJs False) $ staticApp $ defaultWebAppSettings "frontend")
, but I don't know how we can specify stylesheets like in our static HTML since we can't seem to get at the document's head.fail "unknown example"
isn't called when passing an invalid CLI argument.nix develop
shell. I'm not totally sure why, but Cabal otherwise fails in fairly inscrutable ways.