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