Fork me on GitHub
#reagent
<
2015-12-14
>
roelof06:12:26

I see a lot of examples where hiccup is used. Can I also use selmer instead of hiccup

roelof06:12:09

pity, I liked the way I can use template inheritance with selmer.

roelof06:12:32

but I saw a way I can do this another way with hiccup

mikethompson06:12:45

hiccup certainly has the problem of not being "designer friendly", but it is a very powerful templating system, because you have the full power of a programming language at your disposal.

mikethompson06:12:05

So "template inheritance" should be a piece of cake

roelof06:12:47

I know, but I have a site with more then 10 pages and all pages needs the same header and footer

mikethompson06:12:16

Doesn't that just mean the header and footer are components?

roelof06:12:27

in fact it does. I use them on all the pages

mikethompson06:12:03

(defn   page 
     [main]
     [:div   
           [header]
           [main]
           [footer]])

mikethompson06:12:14

pass the main bit into the page

mikethompson06:12:13

Anyway, I guess I'm just saying that hiccup is the equal of any templating system.

roelof06:12:10

I see the idea . I can put it all the code of the header and the footer. so only main has to be filled in

mikethompson06:12:18

Yep, you have a complete programming language at your disposal. I don't quite know why you would do the following, but it shows that hiccup is just a returned data structure :

(defn page 
    [main]
    (into [:div]  (map  vector [header main footer])))

grav09:12:42

Hey! I get a lot of these: Warning: reagent19.getDOMNode(...) is deprecated. Please use ReactDOM.findDOMNode(instance) instead

grav09:12:23

Cannot find any issues on Reagent’s Github. And I’m running newest versions of Reagent. None of my code is calling getDOMNode directly

sveri09:12:52

Hi, I find myself often that for the need of keys in "for" loops I want to reach for the counter of the seq. This leads to code that does not (for [x xs]... but (for [n (range 0 (count xs)]...(nth xs n)... Is there a more idiomatic solution for this problem?

naomarik09:12:02

i'd love to know this too

naomarik09:12:24

ruby has .each_with_index

jaen09:12:29

Well, there's map-indexed and keep-indexed

jaen09:12:01

If you need a for comprehension (wouldn't call it a loop) with index then I'd zip the sequence with the range.

jaen09:12:17

For some reason Clojure doesn't have zip but you can easily implement it

jaen09:12:24

I quite like this implementation:

(defn zip
  "Zips collections."
  [& colls]

  (partition (count colls) (apply interleave colls)))

sveri09:12:53

@jaen: Hm, I dont understand how that zip helps? It returns this for me: (zip ['a 'b 'c]) => ((a) (b) (c))

sveri09:12:24

Ah, ok, it's not for the index, but just the "splitting" part

jaen09:12:39

Well, you can do (for [[idx elem] (zip (range) your-coll)] ...) if you need indices

jaen10:12:14

You can't do (for [idx (range) elem your-coll] ...) since that will result in a cartesian product, right?

sveri10:12:52

I did not see that I could provide (range) to as a parameter

sveri10:12:57

Nice one, thank you very much

jaen10:12:09

You can do anything

jaen10:12:23

It basically creates tuples of corresponding elements of seqs

jaen10:12:59

(zip [1 2 3] [4 5 6] [7 8 9]) will net you [[1 4 7] [2 5 8] [3 6 9]]

jaen10:12:14

Kind of like specifying more args to map or filter.

jaen10:12:51

It's probably less popular in Clojure than in Haskell, since Clojure has varargs, but it can be useful nonetheless.

sveri10:12:57

Yea, I got that, but totally thought not of applying range to it too

jaen10:12:12

Gotcha. Well, it's a seq like any other after all ; d

sveri10:12:30

yea, lazyness ftw simple_smile

mccraigmccraig10:12:33

@jaen: u can also zip with smth like (map vector (iterate inc 0) some-seq)

jaen10:12:00

Yeah, I know about the map-the-vector trick, but I prefer to have a function defined, it's less cryptic that way.

jaen10:12:07

Hence why I did not suggest that.

jaen10:12:53

It would be interesting though to see how mapping vector compares performance wise to that implementation.

sveri10:12:09

Premature Opimization! ;D

grav10:12:15

@sveri: If you use map, you don’t have to restrict the range of (range).

grav10:12:46

You can just do (map (fn [x i] ...) xs (range)) and it’ll terminate when reaching the end of xs

grav10:12:40

I don’t find map-indexed very idiomatic, it doesn’t seem to compose as well as just mapping over several sequences

mbertheau15:12:08

I remember having seen deref-or-value or similar somewhere, anyone know where?

phil22:12:12

Hey, I'm having issues with the following code: https://gist.github.com/philjackson/a79a7a6756cb0ad5387b

phil22:12:01

When buffer is updated, the first time codemirror appears, from then on though, :component-did-mount doesn't fire.

phil22:12:37

I'm sure I'm being an idot, but being an idot, I can't figure out why.

emil0r23:12:30

hi. is it possible to have a colspan attribute ala [:td {:colspan 6} "stuff here"] in reagent?