This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-01
Channels
- # beginners (15)
- # boot (3)
- # cider (10)
- # clara (2)
- # cljs-dev (19)
- # clojure (31)
- # clojure-uk (9)
- # clojurescript (60)
- # core-async (1)
- # datomic (10)
- # docs (4)
- # fulcro (5)
- # hoplon (33)
- # juxt (1)
- # luminus (1)
- # off-topic (3)
- # om (20)
- # parinfer (2)
- # portkey (61)
- # re-frame (6)
- # reagent (39)
- # shadow-cljs (18)
- # spacemacs (4)
- # specter (8)
oops, sorry
what's the issue you're facing @dhirensr?
{:dependencies [[prone "1.1.4"]
[ring/ring-mock "0.3.1"]
[ring/ring-devel "1.6.2"]
[pjstadig/humane-test-output "0.8.2"]
[binaryage/devtools "0.9.4"]
[com.cemerick/piggieback "0.2.2"]
[doo "0.1.7"]
[figwheel-sidecar "0.5.13"]]
:plugins [[com.jakemccrary/lein-test-refresh "0.19.0"]
[lein-doo "0.1.7"]
[lein-figwheel "0.5.13"]
[org.clojure/clojurescript "1.9.908"]]
:cljsbuild
{:builds
{:app
{:source-paths ["src"]
:figwheel {:on-jsload "myappafsa.core/mount-components"}
:compiler
{
:asset-path "/js/out"
:output-to "assets/www/js/app.js"
:output-dir "assets/www/js/out"
:optimizations :none
:pretty-print true}}}}
:doo {:build "test"}
:source-paths ["env/dev/clj"]
:resource-paths ["env/dev/resources"]
:repl-options {:init-ns user}
:injections [(require 'pjstadig.humane-test-output)
(pjstadig.humane-test-output/activate!)]}
Hoping to get help with something simple. I was trying to replicate one of the examples from http://timothypratley.blogspot.com/2017/01/reagent-deep-dive-part-1.html Having trouble with the following
(def c
(reagent/atom 1))
(defn counter []
[:div
[:div "Current counter value: " @c]
[:button
{:disabled (>= @c 4)
:on-click
(fn clicked [e]
(swap! c inc))}
"inc"]
[:button
{:disabled (<= @c 1)
:on-click
(fn clicked [e]
(swap! c dec))}
"dec"]
])
Even though the prn
does print the updated value after every click, the div with “Current counter value: ” always shows the initial atom value (1). Any ideas?@raheel how do you use counter?
also where's the prn you spoke of?
counter
gets rendered like this:
(defn mount-root []
(reagent/render counter
(.getElementById js/document "app")))
(defn ^:export init []
(mount-root))
oops, prn
was with the inc
button:
[:button
{:disabled (>= @c 4)
:on-click
(fn clicked [e]
(prn @c)
(swap! c inc))}
"inc"]
right
try wrapping counter in another function
(defn root []
[counter])
(reagent/render root (.getElementById js/document "app"))
does that help? also try Shift-Reloading the browser, for shits and giggles
the very first, top-level element doesn't always track Ratom watches properly - it's some kind of known limitation with reagent
I seem to remember it being documented somewhere but can't find it now
anyway i've made it a habit to have a harmless root
component at the top, just to be safe
cool, thanks a bunch @pesterhazy!
sure thing!
you can also try (reagent/render [#'counter] (.getElementById js/document "app"))
- does that work as well?
got it from here: https://github.com/reagent-project/reagent/issues/94#issuecomment-73564259
not sure why this is the case
@juhoteperi may know more?
render
parameter should be a component (i.e. vector), function is not
@juhoteperi it supports functions as well: https://github.com/reagent-project/reagent/blob/master/src/reagent/dom.cljs#L43
if comp
is a function, it's called - but only once, in the context of the initial reagent.dom/render
call
which kind of defeats the purpose of using a component 🙂
a better behavior would be (if (fn? comp) [comp] comp)
I wonder if that would break any existing apps