summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aero/Ibb.hs45
-rw-r--r--pack/ibb.nix20
2 files changed, 64 insertions, 1 deletions
diff --git a/aero/Ibb.hs b/aero/Ibb.hs
new file mode 100644
index 0000000..e357317
--- /dev/null
+++ b/aero/Ibb.hs
@@ -0,0 +1,45 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE RecordWildCards #-}
+
+module Ibb where
+
+import Miso
+import Miso.String
+
+main :: IO ()
+main = startApp App {..}
+ where
+ initialAction = SayHelloWorld
+ model = 0
+ update = updateModel
+ view = viewModel
+ events = defaultEvents
+ subs = []
+ mountPoint = Nothing
+
+type Model = Int
+
+-- | Sum type for application events
+data Action
+ = AddOne
+ | SubtractOne
+ | NoOp
+ | SayHelloWorld
+ deriving (Show, Eq)
+
+-- | Updates model, optionally introduces side effects
+updateModel :: Action -> Model -> Effect Action Model
+updateModel AddOne m = (m + 1) <# do
+ putStrLn "Hiya World" >> pure NoOp
+updateModel SubtractOne m = noEff (m - 1)
+updateModel NoOp m = noEff m
+updateModel SayHelloWorld m = m <# do
+ putStrLn "Hiya World" >> pure NoOp
+
+-- | Constructs a virtual DOM from a model
+viewModel :: Model -> View Action
+viewModel x = div_ []
+ [ button_ [ onClick AddOne ] [ text "+" ]
+ , text (ms x)
+ , button_ [ onClick SubtractOne ] [ text "-" ]
+ ]
diff --git a/pack/ibb.nix b/pack/ibb.nix
index 6bf84d8..d91d119 100644
--- a/pack/ibb.nix
+++ b/pack/ibb.nix
@@ -6,12 +6,30 @@ let
blaze-markup
bytestring
hinotify
+ miso
MonadRandom
random
scotty
shakespeare
text
]);
+ ghcjs_ = pkgs.haskell.packages.ghcjs.override (oldAttrs: {
+ overrides = with pkgs.haskell.lib; self: super: {
+ http-types = dontCheck super.http-types;
+ tasty-quickcheck = dontCheck super.tasty-quickcheck;
+ scientific = dontCheck super.scientific; # takes forever
+ servant = dontCheck super.servant;
+ };
+ });
+ ghcjs = ghcjs_.ghcWithPackages (hp: with hp; [
+ aeson
+ containers
+ ghcjs-base
+ miso
+ protolude
+ servant
+ text
+ ]);
make = ../chip/make;
entrypoint = "Ibb";
in
@@ -20,7 +38,7 @@ stdenv.mkDerivation rec {
version = "0";
src = ../.;
nativeBuildInputs = [
- ghc
+ ghc ghcjs
];
strictDeps = true;
buildPhase = "${ghc}/bin/runhaskell ${make} ibb";