Fork me on GitHub

I use accountant and secretary but i actually don’t know how anchor tags work with html5 history

Ivan Fedorov13:09:23

Stuck on rendering a collection from a reagent atom (initially a re-frame sub, but even direct atom binding doesn’t work). The case is

(def my-db (r/atom {:notes [{:id 1, :text "abc"}, {:id 2, :text "bca"}]}))


(defn my-list []
  (for [n (:notes @my-db)]
    ^{:key (:id n)} [:div.note (:text n)]))
So when I update :texts in :notes of my-db, my-list doesn’t notice the change. It requires participation of changed :text in the key, which is not handy at all. Is there an elegant solution?


@ognivo two things, 1) you'll want to wrap that for inside of a [:div ...], And 2) you'll want to either wrap that for loop in a doall, or lift the deref of that atom outside of the for loop. For is lazy, so the deref won't happen.


And 3) if you are using a hot-reloadinf tool like figwheel, you should use defonce instead of def when defining the my-db ratom

Ivan Fedorov17:09:26

@gadfly361 my bad, I shouldn’t have posted it here, as re-frame app-db is using a re-frame’s ratom in the end, not a direct reagent impl. For re-frame ratom doall application doesn’t help. Also, using shadow-cljs


Typed this from my phone, but this should work for re-frame or vanilla reagent (whether you are using a subscription or a ratom shouldn't make a difference)

(defn my-list []
  (let [ns (:notes @my-db)]
(for [n ns]
    ^{:key (:id n)} [:div.note (:text n)])]))

Ivan Fedorov17:09:49

Yep! My fault all along. It all actually works fine. Reason was at the level of interop with draft-js editor