Fork me on GitHub
#cljfx
<
2023-12-02
>
Jonathan Bennett11:12:05

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

Andrey Subbotin01:12:46

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 Bennett02:12:00

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 Bennett02:12:07

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.