I'm trying to understand example 18 (the pure events example) because it seems to be the most complete canonical example of how to structure a program. But I've got a few questions, first of which being "Is example 18 actually a good example to be modeling my understanding of how to handle state and events on?"
> Is example 18 actually a good example to be modeling my understanding of how to handle state and events on? > Great question! After using cljfx for a long time, I'd say I stopped using all re-frame-isms such as effects/co-effects
I'm doing something like that usually: https://clojurians.slack.com/archives/CGHHJNENB/p1698244379766559?thread_ts=1698241966.505439&cid=CGHHJNENB
Next, what is the :dispatch part of the event handler https://github.com/cljfx/cljfx/blob/2b3f86ab5c7fda9dcffd1149401f63de4604d797/examples/e18_pure_event_handling.clj#L47C10-L47C10 ?
If you're new to the event handling model used, it might make sense to read the re-frame intro, starting here: http://day8.github.io/re-frame/a-loop/ Albeit re-frame is a different library, the concept is the same, and the docs are top notch. chef_kiss The main things to look for are: state, events, subscriptions, co-effects, and effects.
Having said all that, the :dispatch line defines the effect available to the event handler. If your handler returns a map with the key set, the value will be passed to the effect handler specified on the line, namely fx/dispatch-effect , which in its turn will dispatch whatever it gets as a new event.
ah, cool. So dispatch is how I could have an event trigger another event? for example, clicking the "end turn" button at the end of the end phase could fire the ::roll-initiative event before it advanced to the next phase. That way the code for rolling initiative isn't duplicated between the end phase event at the event tied to the "re-roll initiative" button.
I'll give that re-frame tutorial a read, I've seen them mention it several places. I feel like I'm making good progress on this game, this declarative GUI thing is a bit weird sometimes, but I seem to be a lot more productive in it.