Fork me on GitHub
#clojurescript
<
2020-08-14
>
ccann19:08:19

I'm trying to make our web app, which serves compiled ClojureScript, always serve the most up-to-date version, i.e. only use the browser-cached version if there is not a newer version on the server. Adding Cache-Control: no-cache to the response headers and similar meta tags on the HTML hasn't solved the problem. The index file we serve is up to date, but the CSS and compiled JS are not. can anyone advise?

phronmophobic19:08:40

the easiest way is to include the version in the js filename and just update the js <script> src when the version changes.

phronmophobic19:08:26

then you can cache old versions indefinitely

👍 3
johanatan19:08:41

hi, is it possible to use with-redefs to redefine javascript functions, like say js/setTimeout ?

johanatan19:08:05

hmm, repl would seem to indicate 'yes':

cljs.user=> (with-redefs [js/setTimeout (constantly true)] (js/setTimeout :blah :blahzzz))
true

johanatan19:08:51

perhaps a more convincing example:

cljs.user=> (with-redefs [js/setTimeout (constantly :blaaaaaaz)] (js/setTimeout :blah :blahzzz))
:blaaaaaaz

kiranshila22:08:43

Just wanted to show off some cljs on hardware. Pretty neat new use case for the lanugage https://youtu.be/WYSL-fD_ogA

🎉 15
clojure-spin 9
lilactown22:08:21

do you have a link to where I could get the display you’re using? it looks nice. I have an idea for a project

kiranshila22:08:30

They’re pretty cheap for what they are, but ofc you have to wait for the shipping from China.

kiranshila22:08:16

My roomate and I are working on this, and we plan to sell a little kit with a PCB with the ESP32, some sensors, the VFD itself, and a nice case. I’ll keep everyone posted.

lilactown22:08:34

awesome 😄 thanks!

russmatney01:08:33

this is AMAZING!!

parrot 3
clojure-spin 3
p4ulcristian22:08:12

Hello guys. I try to write some recursive function, but I must mess up something with the logic. I wanted to printed it out, but it won't. Does (.log js/console "something") work inside a reduce function?

p4ulcristian23:08:16

hmm, for me it doesnt. If I print to console the data-structure which it resulted, it is okay. But if I want to see the parameters step-by-step, and I try to print them, it won't do it.

p4ulcristian23:08:26

(defn make-some-true [the-map path]
  (.log js/console "success-in2 ")
  (let [result (doall  (convert-indexed-map-to-vector
                         (reduce-kv (fn [till-now now-key now-value]
                                      (if (= (first path) (:name now-value))
                                        (if (not (empty? (rest path)))
                                          (assoc-in
                                            (assoc-in (assoc till-now now-key now-value)
                                                      [now-key :state] true)
                                            [now-key :children]
                                            (make-some-true
                                              (:children now-value)
                                              (rest path)))
                                          (assoc-in (assoc till-now now-key now-value)
                                                    [now-key :state] true))
                                        (assoc till-now now-key now-value)))
                                 {}
                                 the-map)))]

    result))

(defn make-all-false [the-map]
  (.log js/console "success-in")
  (vec (reduce (fn [till-now now]
                 (conj till-now
                       (if (:children now)
                         (assoc now :state false :children (make-all-false (:children now)))
                         (assoc now :state false))))
               []
               the-map)))

(defn assoc-with-values [the-map paths]
  (.log js/console "success")
  (vec (reduce
         (fn [till-now path]
           (doall (make-some-true till-now path)))
         (make-all-false the-map))))

p4ulcristian23:08:49

the print "success-in2" wont get printed out

p4ulcristian23:08:58

success, and success-in does

thheller23:08:01

well what does make-all-false return? maybe thats empty?

p4ulcristian23:08:46

it is not, I printed it out

p4ulcristian23:08:04

it just doesnt work as expected, so I need to debug it.

p4ulcristian23:08:20

(defn assoc-with-values [the-map paths]
  (.log js/console "success"
    (str  (vec (reduce
                 (fn [till-now path]
                   (doall (make-some-true till-now path)))
                 [{:name "something" :children [{:name "deeper" :state false}] :state false}])))))

p4ulcristian23:08:42

I tried it with a vector, so it doesnt depend on it

thheller23:08:49

thats just one value. so the reduce fn isn't called and just returns that value since there is no init provided.

thheller23:08:25

maybe you don't want reduce there? maybe map? or provide an init value

thheller23:08:25

(reduce rfn init coll)

p4ulcristian23:08:06

I check it out.

p4ulcristian23:08:41

omg, I forgot the coll

p4ulcristian23:08:02

it was the paths , forgot to add it to the end

p4ulcristian23:08:18

so there is no mystery, just mistake, thank you very much 😄

👍 3