Skip to content

Commit

Permalink
Added useWarp option to project.
Browse files Browse the repository at this point in the history
  • Loading branch information
ElvishJerricco committed Jun 18, 2018
1 parent 9cd56b0 commit 678e39d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
35 changes: 22 additions & 13 deletions docs/project-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,32 @@ Haskell process. This is recommended to allow testing different
browsers, and to make use of a browser's significantly better
developer tools.

To use it, add `jsaddle-warp` and `reflex-dom-core` to your frontend's
dependencies, and change `main` like so:
To use it, enable the `useWarp` option in `default.nix`.

```haskell
import Language.Javascript.JSaddle.Warp
import Reflex.Dom.Core (mainWidget)
import Reflex.Dom hiding (mainWidget, run)
```nix
# default.nix
(import ./reflex-platform {}).project ({ pkgs, ... }: {
useWarp = true;
main :: IO ()
main = run 3911 $ mainWidget app
packages = {
common = ./common;
backend = ./backend;
frontend = ./frontend;
};
shells = {
ghc = ["common" "backend" "frontend"];
ghcjs = ["common" "frontend"];
};
})
```

This will spawn the Warp server on port 3911, which you can connect
your browser to to run the app. It will also compile under GHCJS as
is, automatically defaulting back to the GHCJS backend. Both
`jsaddle-warp` and `jsaddle-webkit2gtk` are safe to use from GHCi, so
you can test changes even more quickly with `:r`.
Running the GHC-built frontend with this option will spawn the Warp
server on port 3003, which you can connect your browser to to run the
app. It will also compile under GHCJS as is, automatically defaulting
back to the GHCJS backend. Both `jsaddle-warp` and
`jsaddle-webkit2gtk` are safe to use from GHCi, so you can test
changes even more quickly with `:r`.

**Note:** The native backends for JSaddle have much much better
runtime performance than the GHCJS backend. To put it in perspective,
Expand Down
14 changes: 12 additions & 2 deletions project/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ in
# Set to false to disable building the hoogle database when entering
# the nix-shell.

, useWarp ? false
# Configure `reflex-dom` to use `jsaddle-warp`.

, android ? {}
# ::
# { <app name> ::
Expand Down Expand Up @@ -137,8 +140,15 @@ in

}:
let
overrides' = nixpkgs.lib.composeExtensions
(self: super: mapAttrs (name: path: self.callCabal2nix name path {}) packages) overrides;
overrides' = nixpkgs.lib.foldr nixpkgs.lib.composeExtensions (_: _: {}) [
(self: super: mapAttrs (name: path: self.callCabal2nix name path {}) packages)
(self: super: {
reflex-dom = if useWarp && (with self.ghc.stdenv; hostPlatform == targetPlatform) && !(self.ghc.isGhcjs or false)
then nixpkgs.haskell.lib.addBuildDepend (nixpkgs.haskell.lib.enableCabalFlag super.reflex-dom "use-warp") self.jsaddle-warp
else super.reflex-dom;
})
overrides
];
mkPkgSet = name: _: this.${name}.override { overrides = overrides'; };
prj = mapAttrs mkPkgSet shells // {
shells = mapAttrs (name: pnames:
Expand Down

0 comments on commit 678e39d

Please sign in to comment.