Fork me on GitHub
#reagent
<
2015-12-23
>
danbunea06:12:47

@gadfly361: can you tell me more about your book?

si1412:12:20

hi there! how do you deal with multiple classes in Reagent?

si1412:12:16

[:button.btn.btn-sm.btn-default {:class (if (pos? @selected-count) "btn-primary" "btn-default disabled") :on-click #(dispatch [:foo])} "bar"]

si1412:12:23

I mean stuff like this

si1412:12:02

it quickly goes to hell if there are several conditions, e.g.

si1412:12:18

css-class (str (if cursor-enabled "cursor" "") " " (if is-selected "active" ""))

si1412:12:41

this seems somewhat wrong to me. is there some better way to do this?

mccraigmccraig12:12:31

@si14: i do it like this

(->> [(when x "foo")
      (when y "bar")
      (when z "baz")]
     (filter identity)
     (str/join " "))

mccraigmccraig12:12:07

which you can wrap into a function such as

(defn classes
  [& cs]
  (->> cs
       (filter identity)
       (clojure.string/join " ")))

mikethompson12:12:57

Yes, that's the way. I'd probably use (remove nil?) instead of (filter identity)

mikethompson12:12:13

But that's just personal choice

si1412:12:42

thanks. still kinda hacky, but yeah, it's better

mccraigmccraig12:12:54

ha, yeah, that's probably more idiomatic. i think i have stockholm syndrome

mikethompson12:12:11

Very nit picky on my part simple_smile

si1412:12:46

it's just strange to concatenate strings given that classes are (arguably) better represented by keywords

si1412:12:18

(it's more about Hiccup, actually)

si1412:12:32

@mikethompson: yeah, that's awesome! Are you going to merge it?

mikethompson12:12:14

@si14: the equivalent when dealing with styles is to use merge

[:div 
    {:style 
       (merge 
          (when cond1  {:background-color "blue"})
          (when cond2  {:font-size  "24px"})})
     "Hello"]   

mikethompson12:12:16

@si14 I'd love to merge 154, but that's up to Dan

si1412:12:39

@mikethompson: ah, I see. I was confused by your "owner" status in the repo

mikethompson12:12:04

I have some rights, but I defer to Dan who is the original author, and true owner

mikethompson12:12:31

I have the right to triage issues, mostly.

si1412:12:37

tbh, your comment here https://github.com/reagent-project/reagent/issues/212#issuecomment-166458254 seems gloomy. Do you think that Reagent has problems?

mikethompson12:12:04

Dan tends to be very reclusive. And to do his own thing. Not a lot of consultation

mikethompson12:12:23

So that's me whinging

si1412:12:20

somewhat tangential: re-frame was eye-opening for me. thank you simple_smile on the other hand, I've started to see why David did some stuff in Om.Next the way he did. E.g. "automagical" joins and deduplication

si1412:12:48

in general, I like how stuff converges to some common way of doing things, e.g. global state atom with subscriptions.

mikethompson12:12:10

I haven't looked into OM.Next much yet. OM (original) was massively, aggressively hyped, and, while it had a couple of interesting ideas, I thought it had some terrible ideas too. So now there is OM.Next and it is also being massively hyped, I'm cautious to spend many brain cycles on it. I think David's position creates a slight reality distortion effect. I'll wait for it to come out of alpha. simple_smile Who knows, i could be pleasantly surprised. What is interesting to me is MotorCycle.js ... it uses my favorite v-dom library: snabbdom, and it has a very FRP nature. I find that direction really interesting.

si1412:12:07

I'll check that out, thank you!

mikethompson12:12:29

https://github.com/motorcyclejs/core (but to properly understand it, you'll have to look at http://cycle.js.org/)