This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-17
Channels
- # adventofcode (23)
- # announcements (2)
- # aws (11)
- # babashka (181)
- # beginners (59)
- # chestnut (2)
- # clj-kondo (9)
- # clojure (90)
- # clojure-brasil (2)
- # clojure-europe (18)
- # clojure-italy (24)
- # clojure-nl (9)
- # clojure-spec (3)
- # clojure-uk (28)
- # clojured (4)
- # clojuredesign-podcast (3)
- # clojurescript (12)
- # community-development (49)
- # core-async (49)
- # cryogen (5)
- # cursive (16)
- # data-science (1)
- # datascript (7)
- # datomic (54)
- # defnpodcast (4)
- # events (2)
- # figwheel-main (14)
- # fulcro (139)
- # graphql (1)
- # jobs-discuss (6)
- # kaocha (1)
- # luminus (2)
- # malli (3)
- # music (1)
- # off-topic (34)
- # pathom (24)
- # re-frame (13)
- # reitit (5)
- # shadow-cljs (8)
- # test-check (6)
Do people ever create events with compound keys at all, is there a reason not to do it? E.G.:
(rf/reg-event-fx
[:a-key dynamic-key :final-key]
(fn [_ _]
{}))
Not sure about dynamic-key
, but I sometimes use compound keys that are just vectors of keywords. Usually it's just to avoid having to create another multimethod.
Thanks! Yeah, that's what I'm trying avoid as well. dynamic-key
works I was just wondering whether there was some reason to not rely on the compound key that I couldn't see.
Eh, not really a robust reason but some tools don't like them. At least, quite some time go re-frame-10x used to display them incorrectly, IIRC. That seems to be fixed now though. I think there was something with re-frisk as well. But I haven't seen anything like that recently, so yeah, probably nothing to worry about.
And by finding an issue in my code, I immediately realized a downside for this approach. You cannot have default values. For me, this is a significant advantage of multimethods. Of course, there's also dispatch values hierarchy but I don't use it that often.
Ah, that's a good point. I don't have a default in this case but it makes me think I should just stick to multimethods to keep everything consistent.
Compound keys are no different from regular keyword keys. re-frame doesn't care what you use as a key, keywords are just a common practice.
@UFJCSRT2M the keys are just keys in a map https://github.com/day8/re-frame/blob/master/src/re_frame/registrar.cljc#L15
very interesting discussion. @U2FRKM4TW, would you mind giving an example where compound keys are useful please?
@U7ESY38HJ Anywhere you'd use a multimethod but where using one is more clunky and not justified enough to not use a compound key.