Fork me on GitHub

does anyone have any leads on clojurescript libraries for animating diagrams?


It’s a commercial product, and I have no affiliation with it but it is pretty good IMO; I’ve used it years ago, not recently but I assume it’s still good (it’s a JS-library, but as far as I recall, the API is quite data-driven so it feels almost “idiomatic” to use from CLJS)


what kind of diagrams?


visual clojure functions would be sweet.


I'd be curious to know what you'll end up using.


Perhaps something like this could be used: Not a very direct way, but a way.


you could use d3… or an animation library like gasp. gasp timelines as a clojure dsl have been on my mind for quite a while.


@U9VP9VCE6 I can only find GSAP at, not gasp. Do you maybe have a link?


AUTOCOMPLETE FAIL! 😂 you have the right link

👍 2
eric wolf03:08:52

Hi folks. I'm looking for a clojurescript example that does not use react or any framework like that, that modifies the DOM of a web page. Is that possible with pure clojurescript?


Since it's possible with pure JS, it's also possible with pure CLJS. The examples won't be that different from what you see in JS, but you can use some built-in functionality like clojure.browser.dom and maybe shadow.dom if you use shadow-cljs.

eric wolf03:08:07

Thanks, I will take a look at that


i use this light wrapper from karsten schmidt… the create doom from hiccup style is a great time saver


Harrumph. Is there a problem with vector destructuring in macro expansions?

(defmacro with-mxr [& body]
  `(hx/fnc []
     (let [[_ set-state#] (hooks/use-state 0)]
       (rn/set-state-record ~'me set-state#)
       [email protected])))
The error is about the left side of the LET binding not being a symbol or map:
------ ERROR -------------------------------------------------------------------
 File: /Users/kennethtilton/dev/matrix/cljs/mxnative/src/myapp/build.cljs:45:43
  42 |       :rx-dom (cFonce (with-par me
  43 |                         (mkrx
  44 |                           {:name      :root
  45 |                            :rendering (cF (with-mxr
Syntax error macroexpanding cljs.core/let.
Call to cljs.core/let did not conform to spec.
-- Spec failed --------------------

  ([[myapp.mxr-gen/_ set-state__48094__auto__] ...] ... ...)

should satisfy



Am I missing sth simple?


Your _ gets a namespace because of the syntax quote above. Try evaluating

`(let [_ nil])
and you'll see the same thing. To fix that, you can replace _ with

👀 2

Brilliant. Thx! I thought I had tried using a throwaway getter# instead of the _ placeholder, but I guess not. And I did think I saw it complaining about the let binding, but mebbe that was down stream, Thx again. 🙏

👍 2

How does CLJS handle this?

(ns foo.script
  (:require ["fs" :as fs]))

(println (count (str (fs/readFileSync "script.cljs"))))
Does it create a "real" namespace for fs or is fs just the fs object from the library itself? And is fs/readFileSync then translated into an object lookup in this library, or is there a "real" namespace with a readFileSync function created behind the scenes? It seems like it's doing something like the latter:
cljs.user=> (str (fn [] (fs/readFileSync "script.cljs")))
"function (){\nreturn cljs.user.node$module$,\"script.cljs\");\n}"


I'd be interested to know as well 🙂


answered how it works in shadow. maybe that helps 😛


thank you :)


I'm doing some pretty computationally intensive work in ClojureScript with a need to mutate values in place. I decided on using volatile! since it to me seems like the most "bare bones" wrapper around a value that's still mutable within a local scope and since thread safety shouldn't be an issue in the browser. Is there a neater way to do this? As a nonsensical example:

// JS
let a = 0;
for (let i = 0; i < 100; i++) {
  a += i;

; cljs
(let [a (volatile! 0)]
  (dotimes [i 100]
    (vreset! a (+ @a i)))
  (println @a)


Did you consider using loop? To steal an example from clojuredocs:

(loop [x 10]
  (when (> x 1)
    (println x)
    (recur (- x 2)))) 

👆 2

@looveh If you need even more low level you can probably just use a JS object.


(let [x #js {}] (set! (.-foo x) 1) x)


But that is likely similar to using a volatile


@borkdude Yeah, that was my first approach but it started getting out of hand when the number of variables grew, this way the compiler helps a bunch too:

(let [!enabled (volatile! true)
      !min-distance (volatile! 0)
      !max-distance (volatile! js/Infinity)
      !min-zoom (volatile! 0)
      !max-zoom (volatile! js/Infinity)
      !min-polar-angle (volatile! 0)
      !max-polar-angle (volatile! js/Math.PI)
      !min-azimuth-angle (volatile! (- js/Infinity))
      !max-azimuth-angle (volatile! js/Infinity)]


I was a bit surprised to learn that this wouldn't work but I'm sure there's a good reason why it shouldn't 😄

(let [a false]
  (set! a true))


Everything in a (let […]) is a constant, cannot be changed. It’s not like a JS variable. But you can re-declare it…

(let [a false 
      a true])