This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-18
Channels
- # adventofcode (1)
- # bangalore-clj (1)
- # beginners (118)
- # boot (39)
- # cljs-dev (6)
- # cljsrn (1)
- # clojure (62)
- # clojure-mke (1)
- # clojure-nl (6)
- # clojure-russia (51)
- # clojure-spec (8)
- # clojure-uk (9)
- # clojurescript (101)
- # code-reviews (1)
- # cursive (2)
- # datascript (9)
- # datomic (80)
- # emacs (4)
- # hoplon (27)
- # jobs-discuss (1)
- # off-topic (1)
- # om (1)
- # onyx (18)
- # protorepl (2)
- # re-frame (13)
- # reagent (13)
- # rum (9)
- # test-check (23)
Hey everybody. I’m pretty new to Clojure and ClojureScript, really enjoying it so far. I was going through the Reagent introduction and came across this piece of code:
(defn lister [items]
[:ul
(for [item items]
^{:key item} [:li "Item " item])])
I’ve tried looking up the ^{ }
notation, but I can’t seem to find anything about it. Any info or links would be appreciated. Thanks!@ander It's for adding metadata to the following expression. See http://clojure.org/reference/metadata.
@ander, it's a way to specify the react key for collections
it's an aid that helps react track elements in a collection in its tree-diff algorithm
@henriklundahl @pesterhazy Thanks for the help!
and search for "key" here: https://reagent-project.github.io/
Instead of using metadata you can add a map as first argument to the component, like this: [:li {:key item} "Item " item]
.
That’s closer to what I’m used to from my JS days. Metadata seems interesting, if a little spooky right now
the whole metadata thing is a mistake IMO; it's a nice hack but not too necessary really
it's hard to reason about when a collection will retain its metadata
@ander it has already been explained to you that it is metadara, but for extra understanding about the process, have a read through this: http://stackoverflow.com/questions/37164091/how-do-i-loop-through-a-subscribed-collection-in-re-frame-and-display-the-data-a/37186230#37186230