In my halogen project have this eval branch:
eval (SetTest tName next) = do
H.set (State Nothing)
detail <- H.fromAff $ toAff settings $ getTestsByTestname (tName ^. unTestName)
H.set (State (Just detail))
pure next
The toAff bit if off doing AJAX and may take a while to return. In my render function I have
, case ts of
Nothing ->
HH.div [class_ BS.centerBlock]
[HH.i [classes (HH.className <$> ["fa", "fa-spinner", "fa-spin", "loading"])]
[]
]
Just td ->
HH.h3_ [HH.text $ td ^. tdName<<<unTestName]
I'm naively expecting to see a loading spinner when until my aff action returns, but it looks like the eval runs all the way through before the html is rendered. Is this correct?
edit
Turns out this was user error - I was calling my Query in wrong order. Future mes: setting the state does indeed update the ui :-)
No, modifying the state during eval
should indeed trigger a render. Unless your Aff
isn't really async, I'm not sure why you wouldn't be seeing what you expect here.
Have you tried doing something like H.fromAff $ later' 5000 $ pure <some value>
? Where later'
comes from Control.Monad.Aff
and <some value>
is something suitable for detail
. You should see the loading spinner for 5 seconds then, before it resolves to <some value>
.