diff options
author | Ben Sima <ben@bsima.me> | 2019-03-26 16:45:18 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-03-26 16:45:18 -0700 |
commit | 25e9f0415127434f9e2d7d31d2918671b781132b (patch) | |
tree | 604c407829e4601a7f5da41838a1231a06071740 /aero | |
parent | 5d5a5ed8d6d63046ce7452c7a20c6218699b6dfd (diff) |
Add sample aero ibb app
Diffstat (limited to 'aero')
-rw-r--r-- | aero/Ibb.hs | 45 |
1 files changed, 45 insertions, 0 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 "-" ] + ] |