Fork me on GitHub
#clojurescript
<
2021-08-01
>
deleted00:08:33

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

raspasov00:08:07

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 https://www.highcharts.com (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)

javi02:08:48

what kind of diagrams?

sova-soars-the-sora03:08:54

visual clojure functions would be sweet.

p-himik03:08:40

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

p-himik03:08:49

Perhaps something like this could be used: https://github.com/helins/dsim.cljc#animation Not a very direct way, but a way.

javi04:08:01

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.

p-himik04:08:43

@U9VP9VCE6 I can only find GSAP at https://greensock.com/gsap/, not gasp. Do you maybe have a link?

javi04:08:59

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?

p-himik03:08:43

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

javi04:08:37

i use this light wrapper from karsten schmidt… the create doom from hiccup style is a great time saver https://github.com/thi-ng/domus/blob/master/src/core.org

kennytilton09:08:21

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#)
       ~@body)))
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

  simple-symbol?

or

  map?
Am I missing sth simple?

p-himik09:08:15

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
kennytilton12:08:39

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
borkdude11:08:06

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$fs.readFileSync.call(null,\"script.cljs\");\n}"

viesti11:08:06

I'd be interested to know as well 🙂

thheller15:08:30

answered how it works in shadow. maybe that helps 😛

viesti15:08:46

thank you :)

Niclas21:08:01

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;
}
console.log(a);

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

isak16:08:01

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

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

👆 2
borkdude21:08:27

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

borkdude21:08:40

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

borkdude21:08:51

But that is likely similar to using a volatile

Niclas22:08:34

@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)]
  ...
  )

Niclas22:08:21

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))

raspasov22:08:41

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])