A minimalistic ClojureScript interface to React.js
John Oerter 2020-07-25T14:12:37.060100Z

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]                                                                                                                          
             (= :goal-input state) [goal-input the-goal app-state]                                                                                          
             (= :goal-timer state) [goal-timer the-goal]
             (= :goal-retro state) [:h1 "Goal Retro"]))]  

p-himik 2020-07-25T14:14:00.060200Z

I would use case since all of the keywords are static.

p-himik 2020-07-25T14:14:32.060500Z

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.

John Oerter 2020-07-25T14:15:56.060800Z

Ah perfect, thank you. If I use case then I wouldn't need the let anymore to deref the atom right?

p-himik 2020-07-25T14:16:40.061Z

Yep. And all those =.

John Oerter 2020-07-25T14:17:23.061200Z

Nice. Thank you!

p-himik 2020-07-25T14:18:39.061400Z

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.

John Oerter 2020-07-25T14:23:23.061600Z

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?

p-himik 2020-07-25T14:31:34.061800Z

Yeah, but the default needs to be explicit. Just something to keep in mind. Well, it depends. Seems fine in this case.

John Oerter 2020-07-25T18:04:10.062Z

Thanks! I appreciate the help

John Oerter 2020-07-25T18:04:41.062200Z

Yeah coming from c#/typescript it feels weird, but I don't know of a better way at this point