@@ -19,21 +19,27 @@ url = BaseUrl Http "localhost" 8000 ""
1919main :: IO ()
2020main = mainWidget run
2121
22+
2223run :: forall t m. MonadWidget t m => m ()
2324run = do
24− let (getUnit :<|> getInt :<|> doRaw) = client api (Proxy :: Proxy m) (constDyn url)
25− b :: Event t () <- button "Get unit"
26− b' :: Event t () <- button "Get int"
27− res :: Event t (Maybe (), XhrResponse) <- getUnit b
28− res' :: Event t (Maybe Int, XhrResponse) <- getInt b'
29− score <- foldDyn (+) 0 (fmapMaybe fst res')
30− r <- holdDyn "Waiting" $ leftmost [fmap (showXhrResponse . snd) res
31− ,fmap (showXhrResponse . snd) res'
32− ]
33− dynText r
34− el "br" $ return ()
35− text "Total: "
36− display score
25+
26+ -- Name the computed API client functions
27+ let (getUnit :<|> getInt :<|> doRaw) =
28+ client api (Proxy :: Proxy m) (constDyn url)
29+
30+ unitBtn <- button "Get unit"
31+ intBtn <- button "Get int"
32+
33+ unitResponse <- getUnit unitBtn
34+ intResponse :: Event t (Maybe Int, XhrResponse) <- getInt intBtn
35+
36+ score <- foldDyn (+) 0 (fmapMaybe fst intResponse)
37+
38+ r <- holdDyn "Waiting" $
39+ leftmost [fmap (showXhrResponse . snd) unitResponse
40+ ,fmap (showXhrResponse . snd) intResponse
41+ ]
42+ dynText r >> el "br" (return ()) >> text "Total: " >> display score
3743
3844showXhrResponse :: XhrResponse -> String
3945showXhrResponse (XhrResponse stat stattxt rbmay rtmay) =