Make examples runnable with jsaddle-warp
#23
Draft
+144
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.