This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-14
Channels
- # aws (1)
- # bangalore-clj (1)
- # beginners (48)
- # boot (65)
- # braveandtrue (1)
- # cider (1)
- # clara (15)
- # cljs-dev (7)
- # clojure (179)
- # clojure-austin (1)
- # clojure-denmark (2)
- # clojure-greece (68)
- # clojure-italy (7)
- # clojure-russia (41)
- # clojure-serbia (9)
- # clojure-spec (44)
- # clojure-uk (27)
- # clojured (15)
- # clojureremote (20)
- # clojurescript (70)
- # community-development (2)
- # core-async (10)
- # cursive (14)
- # datomic (36)
- # defnpodcast (3)
- # emacs (13)
- # events (13)
- # hoplon (33)
- # immutant (18)
- # instaparse (2)
- # jobs (29)
- # jobs-discuss (71)
- # klipse (38)
- # lein-figwheel (4)
- # leiningen (1)
- # mount (34)
- # off-topic (36)
- # om (3)
- # onyx (51)
- # pedestal (5)
- # perun (8)
- # proton (2)
- # rdf (8)
- # re-frame (33)
- # reagent (24)
- # remote-jobs (1)
- # rum (6)
- # spacemacs (2)
- # specter (14)
- # sql (5)
- # testing (6)
- # untangled (1)
- # vim (10)
- # yada (3)
Is this an anti-pattern in Reagent, or just fine?
(defn foo [arg1] [:div (str arg1)])
(defn bar [arg1 arg2] [:div (str arg1 arg2)])
(defn parent [child]
[:div
child])
[:div
[parent [foo "foo"]]
[parent [bar "1" "2"]]]
Or this:
(defn precalculated []
(let [state (r/atom 10)]
(fn []
[:div
(into [:div] (range @state))
[:button {:on-click #(swap! state inc)}
"Click me button”]])))
I always wonder if Reagent behaves correctly when you dynamically create these vectors or calculate them before passing them as props.why an anti-pattern? can you explain?
afaik that's exactly how reagent is intended to be used 🙂
I saw some strange things with re-rendering in the past. Maybe it was due to the use of (foo …)
vs [foo …]
still works fine
there are a couple of things to look out for when it comes to re-rendering
the most important being lazy sequences (avoid them! 👍 for your into
above)
another is multimethods (avoid)
I've blogged about this: https://presumably.de/reagent-mysteries-part-2-reloading.html
@pesterhazy can you elaborate a bit more / have any resources on the multimethod code smell? Didn't see it on the blog... 🙂
multimethods are aweseome generally
there's a known issue with reagent however where if you use a multimethod as a component, the component doesn't rerender properly
don't have a pointer to a github issue unfortunately
honestly at this point it's more hearsay, but @pupeno ran into it recently as well I believe
it's a shame because multimethods would make for great (polymorphic) components
Thanks for the heads up. It's directly related to some work that I am doing, so I will keep an eye out. Appreciate it...
if you can identify the issue and create a github issue, that'd be great
@pesterhazy I’ve got my React Virtualized Infinite Loader working now btw. Hooked it up with Re-frame. Thanks for the help.
I remember it working fine about six months ago. I picked up the same projects and now it's not working. Really puzzling and annoying.