reflex-dom

getAndDecodeResponseEvent runs 3 times, instead of just once


This little pice of code has me confused:

respCount counts to 3 in case the url exists, to 2 in case of 404, but shouldn't it only count to 1? Also, the actual request gets issued just once.

I'm on the latest develop branch of reflex, reflex-dom

main :: IO ()
main = mainWidget widget

widget :: MonadWidget t m => m ()
widget = do
  postBuildEvt <- getPostBuild
  (respEvt :: Event t (Maybe Data.Aeson.Value)) <- getAndDecode $ "/api/config/ebb7e16b-8954-4320-829c-12d5e4fd3ea9" <$ postBuildEvt
  respCount <- count respEvt
  display respCount
  return () 

Solution

  • When I compile (a slightly different version, modified only to use the warp runner) and run I get "1" and Just "{\"status\":\"ok\"}" in the terminal.
    With GHCJS (whatever version is in reflex-platform as of about 3 weeks ago), I also get "1"