This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-02
Channels
- # adventofcode (97)
- # announcements (11)
- # babashka (18)
- # beginners (34)
- # biff (5)
- # cljfx (5)
- # clojure-europe (4)
- # clojure-uk (2)
- # clojurescript (7)
- # community-development (2)
- # hyperfiddle (8)
- # introduce-yourself (1)
- # music (2)
- # off-topic (2)
- # polylith (3)
- # practicalli (1)
- # releases (1)
- # shadow-cljs (28)
- # squint (1)
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?"
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. 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.