Hi there,
Making my first pleasant steps into elm building a prototype app that does pattern matching on a fairly large data structure loaded from an external source. My question is quite basic, I can imagine a referral to some doc/blog post could do.
The pattern matching is side-effect free and can take from 1 to say 30 seconds. It’s triggered by an onClick
event. This being a prototype, it’s okay for the UI to ‘freeze’ during these calculations (a production version might offload the calculation to a web worker or server-side implementation).
But I would like the UI to show that it’s busy to the user. For this I have a boolean property busy
in my model. The UI is rendered accordingly.
What I’ve not succeeded in is getting the UI to be updated before (busy) and after (not busy) the calculation. I consulted a.o. “How to turn a Msg into a Cmd Msg in Elm?”. My current implementation (ab)uses a sequence of commands (ExecuteScenarioClicked
, ExecuteScenario
, ScenarioExecuted
) during which the busy
status is set True
, the work is performed and the busy
status is set False
.
This does lead to the UI updates I expect when stepping through the debugger. But when running live no update is shown and the UI shows the non-busy status (even during 30 seconds).
So my primary question is when elm decides to rerender parts of the UI. A secondary question is what a suitable pattern would be for achieving an ‘update ui’ - ‘do stuff without side-effects’ - ‘update ui’ cycle would be.
Thanks for any pointers!
Menno