Fork me on GitHub
#reagent
<
2017-10-01
>
dhirensr10:10:08

has anyone here configured cordova with luminus reagent project?

dhirensr10:10:13

needed some help

au-phiware10:10:44

what's the issue you're facing @dhirensr?

dhirensr10:10:59

not able to configure links cordova files with my cljs files

dhirensr10:10:07

{: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!)]}

dhirensr10:10:13

my project.clj

dhirensr10:10:23

and in assets i have my cordova files

raheel18:10:13

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?

pesterhazy18:10:00

@raheel how do you use counter?

pesterhazy18:10:35

also where's the prn you spoke of?

raheel18:10:34

counter gets rendered like this:

(defn mount-root []
  (reagent/render counter
                  (.getElementById js/document "app")))

(defn ^:export init []
  (mount-root))

raheel18:10:05

oops, prn was with the inc button:

[:button
    {:disabled (>= @c 4)
     :on-click
     (fn clicked [e]
       (prn @c)
       (swap! c inc))}
    "inc"]

pesterhazy18:10:22

try wrapping counter in another function

pesterhazy18:10:53

(defn root []
  [counter])

(reagent/render root (.getElementById js/document "app"))

pesterhazy18:10:38

does that help? also try Shift-Reloading the browser, for shits and giggles

raheel18:10:33

would you mind please explaining briefly why this makes a difference?

pesterhazy18:10:35

the very first, top-level element doesn't always track Ratom watches properly - it's some kind of known limitation with reagent

pesterhazy18:10:18

I seem to remember it being documented somewhere but can't find it now

pesterhazy18:10:03

anyway i've made it a habit to have a harmless root component at the top, just to be safe

raheel18:10:27

cool, thanks a bunch @pesterhazy!

pesterhazy18:10:36

you can also try (reagent/render [#'counter] (.getElementById js/document "app")) - does that work as well?

raheel18:10:07

ah yes, that does too. Just another way of wrapping a top-level function?

pesterhazy18:10:17

not sure why this is the case

juhoteperi18:10:04

render parameter should be a component (i.e. vector), function is not

pesterhazy20:10:37

if comp is a function, it's called - but only once, in the context of the initial reagent.dom/render call

pesterhazy20:10:08

which kind of defeats the purpose of using a component 🙂

pesterhazy20:10:06

a better behavior would be (if (fn? comp) [comp] comp)

pesterhazy20:10:28

I wonder if that would break any existing apps