cljfx

Jonathan Bennett 2023-12-02T11:49:05.157979Z

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?"

vlaaad 2023-12-03T15:49:01.171949Z

> 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

Jonathan Bennett 2023-12-02T11:52:18.177319Z

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 ?

Andrey Subbotin 2023-12-03T01:40:46.446609Z

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.

Jonathan Bennett 2023-12-03T02:43:00.230879Z

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.

Jonathan Bennett 2023-12-03T02:44:07.722169Z

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.