I have a problem with trying to Query nested Halogen components. Here is as minimal an example as I could produce. Only the last “handleQuery” is particularly important. It rest of it renders a tree structure and provides a button to recursively query and then log the component nodes to reconstruct the tree data-structure. (The point of this is eventually to make the nodes, and hence the data structure, editable.)
The error message is the same one I get for the original version I started with, and it only occurs when I try to Query in a recursive loop. This last bit makes me wonder whether the message is a bit off. It looks like I need to unpack the value somehow, but I’ve tried all sorts of methods to do this, to no avail.
Any ideas how I get around this? Thanks in advance.
I don’t know if I remember correctly but I think it’s a similar issue here:
requests you make are actions so
mapWithIndex does not work great here - but there is
forWithIndex in Data.TraversableWithIndex and this should do the job:
:: ∀ action a
. Query a
-> H.HalogenM Ministate action Slots o m (Maybe a)
handleQuery = case _ of
GetContent reply -> do
node <- H.get
case node of
Value n -> pure $ Value n
Branch xs -> do
nodeContents <- forWithIndex xs (\i _ -> fromMaybe (Branch ) <$> H.request _cell i GetContent)
pure $ Branch nodeContents
pure $ Just $ reply res
PS: what’s a bit strange for your example here is, that you basically have all the state/structure in the parent-component anyway.
Why not have the component’s state be either a value or a list of child-components (decide for example via init)?
Ok, thanks, I’d gotten a bit too stuck in my idea of what was happening to notice what it was actually doing.
On the PS, yes in this version its a bit pointless, but now I want to add the ability to edit the value of a component. Then it will be useful to run the Query, to collect the up to date values that the user enters/sees.
Thanks for the help.