Fork me on GitHub
#reagent
<
2016-05-02
>
bojan.matic10:05:17

is the snapshot version doing the same as this:

bojan.matic10:05:31

[cljsjs/react "15.0.1-1"]
                 [cljsjs/react-dom "15.0.1-1"]
                 [reagent "0.6.0-alpha" :exclusions [cljsjs/react cljsjs/react-dom]]]

bojan.matic10:05:53

or are there other changes?

bojan.matic15:05:12

can someone explain to me how ^{:key 1} [div] works? I don't understand why the syntax is like that, instead of [:div {:key 1}]

escherize15:05:40

That's attaching metadata, @bojan.matic, which reagent uses to tell react what the keys should be.

escherize15:05:00

both will typically work.

escherize15:05:32

sometimes there's an issue like... [:div '([:h1 "O"] [:h1 "X"])]

escherize15:05:59

where having {:key 1} inside one of those nested :h1's will not work properly.

escherize15:05:15

actually so if you go here you can see that problem: http://cljsfiddle.com/#gist=99cf69414d4f49be3b154c115b938361

escherize15:05:40

in the console there's our favorite warning about Every element in a seq should have a unique :key: ([:h1 "O"] [:h1 "X"]) 😒

escherize15:05:11

in fact, here you can see what (into [:div] ... does: http://cljsfiddle.com/#gist=709027a0c4de0f70280ef5a265c42a4b

bojan.matic15:05:27

what is the ^{:key} syntax? how does the property get inserted into the element that is a sibling there?

bojan.matic15:05:35

what is the ^ character?

bojan.matic15:05:44

that's what i'm not getting

plexus15:05:39

@bojan.matic: every Clojure object can have "metadata" attached to it

looselytyped15:05:40

@bojan.matic: Its a special char in Clojure that helps to set metadata

bojan.matic15:05:28

so is the ^ character a macro?

plexus15:05:33

metadata is extra information that doesn't influence the value of something, so two things can have different metadata but still be considered equal

plexus15:05:05

it's interpreted by the reader, and the data is attached to the value that follows

bojan.matic15:05:11

reader macro?

looselytyped15:05:19

Clojure has a reader macro

plexus15:05:27

yes, a reader macro, exactly

bojan.matic15:05:52

ok, that explains it

bojan.matic15:05:55

thanks a lot! simple_smile

bojan.matic15:05:05

i thought i read somewhere that clojure does not have reader macros?

plexus15:05:19

you can't add your own reader macros

looselytyped15:05:26

Clojure does not allow you to add your own ...

plexus15:05:40

it does have "tagged literals" which lets you accomplish some of the same stuff

looselytyped15:05:19

(I am going to stop typing - it seems @plexus and I have the same thoughts in the same sequence ... like Slack echo in here 😄 )

plexus15:05:01

or I should stop 😄 I'm sure we can complement each other 😉

plexus15:05:31

metadata is used a lot by clojure itself on vars, e.g. try this

plexus15:05:38

(meta #'clojure.core/str)

plexus15:05:13

whether a var is private, whether it can be rebound, the doc string, are all attached as metadata

plexus15:05:39

also clojure.test defines vars that have the test code attached as ^{:test (fn [] ...)} metadata (and you can add ^{:test ...} inline to your functions and the test runner will pick it up

bojan.matic15:05:50

i also see how it gives totally different output in cljs repl