Fork me on GitHub
#clojurescript
<
2020-12-16
>
mokr09:12:57

Hi, does anyone know of a Clojurescript (graph) library that would allow me to throw a lot of node and link descriptions at it and then answer questions like: “How many separate (disconnected) graphs did you end up with?” And related: “What are the start nodes?“. My use case have directed links/edges, btw. I currently have a working solution that generate the input I need for a force directed visualisation in D3.js, but I believe it would open up new possibilities if I rewrote it to be powered by actual graph technology. I was hoping to use Ubergraph for this, but it does not support Clojurescript. Then I looked at Loom, but skimming the docs I’m not so sure it can answer those two questions.

p-himik09:12:26

For your first question, https://github.com/aysylu/loom has the connected-components function. For the second one, I'm not sure whether it has something but it should be easy to check manually by iterating over all nodes and checking that they only have outgoing edges. Of course, you will have to handle situations where there are many such notes (many "starts").

p-himik09:12:41

Some other potentially useful libraries are mentioned here: https://github.com/simongray/clj-graph-resources

mokr09:12:13

Thanks, @U2FRKM4TW, this helps

mokr09:12:11

I suspect I should look into something like adjacency matrices as well, but then I need to find something that allows me to use it without investing serious amounts of time to relearn everything I once knew about matrices. Right now I’m looking for low handing fruits…

Dennis Tel10:12:59

hello 👋, I have a simple clojurescript that simply does a println of hello world. If I build using lein with advanced optimisations I get a file of around 95kb. Is this expected? I thought the google closure compiler would optimize it to the bare minimum?

Dennis Tel11:12:13

Ah I was using println instead of js/console.log, which makes a drastic difference

Dennis Tel11:12:20

hmmm as soon as I unclude a (defn hello [] (js/console.log "hello")) definition its 95kb again…

p-himik11:12:21

I just compiled

(ns clj-playground.single)

(defn hello [] (js/console.log "hello"))

(hello)
with shadow-cljs with these build arguments:
:compiler-options {:output-feature-set :es6}
:js-options       {:babel-preset-config {:modules "commonjs"
                                         :targets "chrome > 70"}}
It resulted in a 219 characters JS file.

Dennis Tel11:12:49

ah maybe I should elaborate: I’m using Lein with cljsbuild. I’m trying to setup a project to create a library that can be used both from the JVM and from JavaScript.

(ns clojure-multi-test.core)

(defn hello []
  #?(:clj  (println "Hello from Clojure")
     :cljs (js/console.log "Hello from ClojureScript!")))

(hello)
:cljsbuild {:builds [{:source-paths ["src"]
                        :compiler    {:output-to     "resources/public/js/main.js"
                                      :optimizations :advanced
                                      :target :bundle
                                      :pretty-print  false}}]}

Dennis Tel11:12:25

Is clsjbuild still a viable solution or should I integrate shadow-cljs into lein?

p-himik11:12:49

Interestingly, in my case hello was just inlined there. No idea about cljsbuild, sorry. I've been using shadow-cljs for years now, cannot complain at all.

p-himik11:12:04

Let me try with the conditionals first though.

Dennis Tel11:12:03

shadow-cljs does seem more advanced/appropriate but as a clojure n00b i’m still trying to figure out what a nice project/build setup would be for this

p-himik11:12:06

Yep, still works just fine, still inlines hello.

Dennis Tel11:12:39

:thinking_face:

p-himik11:12:44

FWIW, my perfect setup is shadow-cljs + clj CLI (i.e. tools.deps.alpha).

Dennis Tel11:12:57

yeah I’ve heard about clj

Dennis Tel11:12:18

might give that one a try. Probably can also build JARs with that 😄

p-himik11:12:55

You might be interested in this project then: https://github.com/seancorfield/depstar

Dennis Tel11:12:04

ehhh that seems pretty complex 😄

Dennis Tel11:12:44

But i’ll have a more in depth look, thanks for the suggestion 🙂

p-himik11:12:54

Leiningen approach (that I don't really like) - have everything under one roof, promote plugin creation, inadvertently assist creating a closed ecosystem. CLJ CLI approach (that I do like) - have a tool that can run anything, allow anything, explicitly promote an open ecosystem.

Dennis Tel11:12:09

First i’ll try to get shadow-cljs setup using CLJ

p-himik11:12:37

Make sure to at list skim through shadow-cljs documentation - it's really good and answers 99% of all questions, including the setup.

Dennis Tel11:12:32

:thumbsup: kudos to you sir!

👍 3
Dennis Tel11:12:58

Just one question though: How do I prevent the closure compiler to strip a namespace/function definitions if I want to make a library?

p-himik11:12:36

If the library is to be used by CLJS, you don't need to do anything because you won't be shipping the compiled code. If it's to be used by JS, then just add ^:export metadata to the symbol: https://clojurescript.org/reference/advanced-compilation#access-from-javascript

Dennis Tel12:12:09

@U2FRKM4TW awesome, got it working using shadow-cljs and have a 825 byte node-library now 😄 Next step is setting up a repl and a jvm build, thank you very much for getting me started 😄!

p-himik12:12:45

Awesome! Good luck and have fun. :)

tvaughan12:12:18

I'm trying to interop with svg-edit, and it has an api that looks like:

svgCanvas.setSvgString('string')(function (data, error) {
     if (error) {
     // There was an error
     } else {
     // Handle data
     }
});
I don't understand this syntax, specifically how the callback is being passed in. Is it possible to make use of this in clojurescript? What would that look like? Thanks

Renato Alencar12:12:32

It would be probably something like this:

((.setSvgString svgCanvas "string") (fn [data error]
                                      (if error
                                        ;; handle error
                                        ;; handle data)))

3
tvaughan13:12:22

Ah, ok. That makes sense. Thanks @U014XLW158T

Renato Alencar13:12:30

I'm glad to help