This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-23
Channels
- # aleph (9)
- # beginners (30)
- # boot (42)
- # carry (1)
- # cider (148)
- # clara (2)
- # cljsrn (13)
- # clojars (2)
- # clojure (90)
- # clojure-dev (1)
- # clojure-dusseldorf (2)
- # clojure-italy (7)
- # clojure-madison (1)
- # clojure-quebec (1)
- # clojure-russia (19)
- # clojure-sg (1)
- # clojure-spec (14)
- # clojure-uk (90)
- # clojurebridge (1)
- # clojurescript (70)
- # clr (7)
- # core-async (24)
- # cursive (26)
- # data-science (2)
- # datascript (3)
- # datomic (46)
- # devops (2)
- # emacs (6)
- # events (1)
- # figwheel (2)
- # hoplon (200)
- # klipse (2)
- # ldnclj (1)
- # lein-figwheel (4)
- # leiningen (3)
- # off-topic (44)
- # om (70)
- # other-languages (6)
- # pedestal (5)
- # protorepl (1)
- # re-frame (17)
- # reagent (14)
- # schema (2)
- # spacemacs (1)
- # specter (3)
- # test-check (38)
- # unrepl (38)
- # untangled (19)
- # yada (16)
Hi! I'm struggling a little with a form-2 clock-like component. There seems to be one extra call to the render function under some circumstances. I've reduced it to the shortest example possible, but I still can't seem to grasp what's going under the hood.
(defn error-panel [outer-ratom]
(let [now (reagent/atom (.now js/Date))
interval 1000]
(fn [inner-ratom]
;; If we de-ref inner-atom or outer-atom here, the setTimeout fn is called twice
;; (print (str @now)) ;; works fine
;; (print (str inner-ratom)) ;; works fine
;; (print (str @inner-ratom)) ;; this triggers a double call
;; (print (str @outer-ratom)) ;; this triggers a double call
(js/setTimeout #(swap! now (partial + interval)) interval)
[:p @now])))
I'd be thankful for any directions!@aisamu I can't really reproduce it. I can see the double "#(swap! .." call only on hot reloading in figwheel/devcards. But this may be due to the page re-render triggering the evaluation of component body and then very soon the previous timer fires.
@aisamu not sure if this is your problem, but you shouldn't do side-effectful stuff in the render fn. The right place for that would be the component-did-mount and component-will-receive-props lifecycle methods
maybe it would help if you could articulate your surprise in terms of expectations and actual behavior?
also reproducing it in klipse would help, like this: http://app.klipse.tech/?cljs_in.gist=viebel/9c0201a060d75b2c722d4e77dbf79907&container=1
@metametadata Rats, it appears to be a figwheel-only issue after all! Thanks for that!
@pesterhazy re: expectations and actual behavior - since the props didn’t change, I wasn’t expecting two calls to the render function. I agree that side-effects should be separated, but I took this pattern straight from Reagent’s intro 😅! (https://reagent-project.github.io - timer-component)
haha oops
we should fix the reagent tutorial 🙂
[:> js/Foo ...]
is shorthand for (def foo (r/adapt-react-class js/Foo)) ... [foo ...]
thx)