This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-25
Channels
- # 100-days-of-code (3)
- # beginners (80)
- # cider (53)
- # cljdoc (9)
- # cljs-dev (66)
- # cljsrn (6)
- # clojure (108)
- # clojure-austin (5)
- # clojure-dusseldorf (1)
- # clojure-italy (9)
- # clojure-losangeles (2)
- # clojure-nl (4)
- # clojure-spec (40)
- # clojure-uk (46)
- # clojurescript (60)
- # cursive (119)
- # datomic (28)
- # emacs (10)
- # events (1)
- # figwheel-main (21)
- # fulcro (16)
- # hyperfiddle (10)
- # immutant (2)
- # leiningen (1)
- # liberator (5)
- # nyc (1)
- # off-topic (36)
- # onyx (4)
- # pedestal (52)
- # portkey (5)
- # re-frame (11)
- # reagent (11)
- # shadow-cljs (46)
- # sql (1)
- # unrepl (2)
I use accountant and secretary but i actually don’t know how anchor tags work with html5 history
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 :text
s 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. https://github.com/reagent-project/reagent/issues/18
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
@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)]
[:div
(for [n ns]
^{:key (:id n)} [:div.note (:text n)])]))
Yep! My fault all along. It all actually works fine. Reason was at the level of interop with draft-js editor
@gadfly361 thanks a lot! 🙂