This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-24
Channels
- # announcements (1)
- # aws (2)
- # beginners (147)
- # boot (19)
- # cider (57)
- # clara (52)
- # cljdoc (18)
- # cljs-dev (14)
- # cljsrn (4)
- # clojure (176)
- # clojure-conj (9)
- # clojure-dev (9)
- # clojure-germany (2)
- # clojure-italy (4)
- # clojure-spec (13)
- # clojure-uk (56)
- # clojurescript (72)
- # code-reviews (11)
- # cursive (17)
- # data-science (1)
- # datomic (52)
- # duct (26)
- # emacs (6)
- # events (9)
- # figwheel (1)
- # figwheel-main (21)
- # fulcro (132)
- # funcool (1)
- # graphql (3)
- # jobs-discuss (42)
- # leiningen (3)
- # luminus (45)
- # mount (10)
- # off-topic (2)
- # re-frame (17)
- # reagent (12)
- # reitit (20)
- # ring-swagger (7)
- # rum (3)
- # shadow-cljs (256)
- # slack-help (15)
- # sql (7)
- # tools-deps (50)
- # uncomplicate (1)
- # yada (9)
In Reagent app, what is the different between these two in the hiccup section: (my-func param1 param2) [my-func param1 param2] Both work the same as far as I can tell.
@artur https://github.com/reagent-project/reagent/blob/master/doc/UsingSquareBracketsInsteadOfParens.md
the pithy answer is: no brackets = no component. brackets don’t immediately invoke the my-func
function. instead a vector is returned and reagent will create a react component associated with my-func
. if you invoke my-func
directly, reagent never even learns about it.
so we just ran into that annoying bug in prod where a component was written like so:
(defn my-component []
(let [my-atom (r/atom {:value 0})
my-value (:value @my-atom)]
(fn [] [:div my-value])))
sure--it’s hard to say exactly how because your example doesn’t show how the atom could ever be updated.
in real life it's a function that fetches data and returns an atom that represents the state of that request
I ended up doing something like this:
(t/deftest my-component-update
(let [test-atom (atom {:value 0})]
(with-redefs [create-atom (fn [_ _ _] test-atom)]
(let [render-fn (my-component)]
(t/is (test.helpers/tree-contains (render-fn) 0))
(swap! test-atom assoc :value 1)
(t/is (test.helpers/tree-contains (render-fn) 1)))))