Skip to content

Commit 72d5414

Browse files
committed
Add changes after review of @Mikolaj
1 parent 4c011f4 commit 72d5414

File tree

1 file changed

+7
-7
lines changed
  • content/case-study-foreign-integration-js-browser

1 file changed

+7
-7
lines changed

content/case-study-foreign-integration-js-browser/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ however it is both outdated (being a GHC fork requiring separate maintenance; cu
5151
During this journey I was using [purescript-halogen](https://github.com/purescript-halogen/purescript-halogen) library - a typesafe, declarative VDOM framework based on [The Elm Architecture](https://guide.elm-lang.org/architecture/).
5252

5353
However, with all the joy that the Haskell-like web programming brought me, I couldn't shake the feeling that there is a room for improvement. From the small things that are
54-
always annoying in polyglot stacks (like FE-BE JSON encoding discrepancies or lack of code sharing), to sometimes very illegible `purs` compiler error messages and of course lack of a lot of language features. This is not my intention to criticize - for a language this small I was amazed by the number and quality of existing tools and frameworks and a plenty of documentation; the overall experience exceeded my expectations by far. I would still recommend PureScript to anyone that wants a lightweight, easy to setup web language with strong type system.
54+
always annoying in polyglot stacks (like FE-BE JSON encoding discrepancies or lack of code sharing), to sometimes very illegible `purs` compiler error messages and of course lack of a lot of language features. This is not my intention to criticize - for a language this small I was amazed by the number and quality of existing tools and frameworks and plenty of documentation; the overall experience exceeded my expectations by far. I would still recommend PureScript to anyone that wants a lightweight, easy to setup web language with strong type system.
5555

5656
However the mentioned shortcomings were why I was closely following the development of the GHC JS backend, wishing to port the `purescript-halogen` library to GHC as soon as it's possible. A fruit of this labour was recently released as [haskell-halogen](https://github.com/Swordlash/haskell-halogen).
5757

@@ -182,7 +182,7 @@ const buttonRipple = new MDCRipple(element);
182182
- Destroy the element once it's removed from DOM: `buttonRipple.destroy()`.
183183

184184
With this, we can start implementation!
185-
file: example2/src/Button.hs
185+
file: [example2/src/Button.hs](https://github.com/Swordlash/halogen-blog/blob/master/example2/src/Button.hs)
186186

187187
First, a few imports:
188188
```haskell
@@ -302,7 +302,7 @@ mateusz@m12844:~/personal/halogen-blog$ ./run_example 2
302302
```
303303

304304
Oof. `google-closure-compiler` doesn't like our `import`. And it makes total sense, since it checks for undefined variables, so it doesn't know what are we importing.
305-
Now, there isn't an easy way to fix this. We would essentially have to pass it all `node_modules` in question - unfortunately the webpack plugin is outdated to Webpack 4.
305+
Now, there isn't an easy way to fix this. We would essentially have to pass it all `node_modules` in question - unfortunately the webpack plugin is outdated; stuck at version Webpack 4.
306306

307307
However, there is a workaround if you really like `google-closure-compiler`, and want to use it. What we can do is not bundle the `js-sources`, but instead create externs
308308
file for the closure compiler, and bundle the actual implementation later with webpack. To prevent name mangling just in case we hook our functions into `window` variable, like
@@ -321,7 +321,7 @@ foreign import javascript unsafe "window.Halogen.init_ripple" initRipple :: HTML
321321
foreign import javascript unsafe "window.Halogen.destroy_ripple" destroyRipple :: MDCRipple -> IO ()
322322
```
323323

324-
Now we add it to our `google-closure-compiler` invokation:
324+
Now we add it to our `google-closure-compiler` invocation:
325325
```sh
326326
mateusz@m12844:~/personal/halogen-blog$ ./run_example 2-workaround
327327
(...)
@@ -465,12 +465,12 @@ The above article shows how to use the JavaScript backend effectively and integr
465465
466466
What's next? There is still a lot to do in terms of code size & performance, as well as integration with other tools:
467467
468-
- This cabal [PR](https://github.com/haskell/cabal/pull/10722) adds a new field, `js-options`, that allows to pass custom flags to `js-sources` preprocessor.
468+
- This cabal [PR](https://github.com/haskell/cabal/pull/10722) adds a new field, `js-options`, that allows passing custom flags to `js-sources` preprocessor.
469469
Notably that would enable i.e. conditional compilation of traces along the lines of `#ifdef XXX <put-trace>` in foreign library code and `if flag(trace-flag) js-options: -optJSP-DXXX` in cabal file.
470470
- Low-hanging fruits like [adding multiline strings support to inline foreign imports](https://gitlab.haskell.org/ghc/ghc/-/issues/25633).
471-
- Bigger [integration efforts](https://gitlab.haskell.org/ghc/ghc/-/issues/25469) with npm.
471+
- [Integration efforts](https://gitlab.haskell.org/ghc/ghc/-/issues/25469) with npm.
472472
473-
What is still a small unknown is deeper integration of the GHC build pipeline with `webpack` build pipeline, in the spirit of gathering `npm` libraries that need to be installed for each Haskell dependency, like `@material/button` in the above example.
473+
What is still a minor unknown is deeper integration of the GHC build pipeline with `webpack` build pipeline, in the spirit of gathering `npm` libraries that need to be installed for each Haskell dependency, like `@material/button` in the above example.
474474
I believe there will have to be a way of declaring inside the cabal package an `npm` dependency (something like the existing `pkgconfig-depends`) and
475475
a webpack plugin will be created for loading haskell package for bundling.
476476

0 commit comments

Comments
 (0)