This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-25
Channels
- # announcements (1)
- # babashka (3)
- # beginners (48)
- # calva (1)
- # clj-kondo (1)
- # cljs-dev (6)
- # clojure (29)
- # clojure-europe (15)
- # clojure-spec (1)
- # clojure-uk (8)
- # clojurescript (17)
- # conjure (23)
- # css (7)
- # cursive (16)
- # datascript (1)
- # emacs (4)
- # fulcro (32)
- # hoplon (3)
- # keechma (16)
- # leiningen (1)
- # luminus (1)
- # meander (11)
- # off-topic (18)
- # pathom (15)
- # re-frame (12)
- # reagent (12)
- # reitit (5)
- # reveal (5)
- # spacemacs (5)
- # xtdb (18)
Is this an idiomatic way to switch between different states of my app? I'm using cond with a keyword atom for each state.
[:main.inner.cover.flex-1 {:role "main"}
(let [state @app-state]
(cond
(= :goal-input state) [goal-input the-goal app-state]
(= :goal-timer state) [goal-timer the-goal]
(= :goal-retro state) [:h1 "Goal Retro"]))]
Regarding the usage of the ratom itself - I think it's OK. But it's a very small case, it's hard to do something "bad" here.
Ah perfect, thank you. If I use case
then I wouldn't need the let anymore to deref the atom right?
Nice. Thank you!
Ah, there's one difference between cond
and case
that may be important.
With cond
, if state
is not equal to any of the keywords, the value will be nil
.
But with case
, there will be an exception.
Ah okay. But I can provide a default as well, right? Also, are keywords the best way to represent these states? Is there a better way?
Yeah, but the default needs to be explicit. Just something to keep in mind. Well, it depends. Seems fine in this case.
Thanks! I appreciate the help
Yeah coming from c#/typescript it feels weird, but I don't know of a better way at this point
You could also use multimethods or reitit for doing the routing.