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.
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").
Some other potentially useful libraries are mentioned here: https://github.com/simongray/clj-graph-resources
Thanks, @p-himik, this helps
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…
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?
Ah I was using println instead of js/console.log, which makes a drastic difference
hmmm as soon as I unclude a (defn hello [] (js/console.log "hello"))
definition its 95kb again…
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.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}}]}
Is clsjbuild still a viable solution or should I integrate shadow-cljs into lein?
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.
Let me try with the conditionals first though.
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
Yep, still works just fine, still inlines hello
.
:thinking_face:
FWIW, my perfect setup is shadow-cljs + clj CLI (i.e. tools.deps.alpha).
yeah I’ve heard about clj
might give that one a try. Probably can also build JARs with that 😄
You might be interested in this project then: https://github.com/seancorfield/depstar
ehhh that seems pretty complex 😄
But i’ll have a more in depth look, thanks for the suggestion 🙂
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.
First i’ll try to get shadow-cljs setup using CLJ
Make sure to at list skim through shadow-cljs documentation - it's really good and answers 99% of all questions, including the setup.
:thumbsup: kudos to you sir!
Just one question though: How do I prevent the closure compiler to strip a namespace/function definitions if I want to make a library?
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
@p-himik 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 😄!
Awesome! Good luck and have fun. :)
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? ThanksIt would be probably something like this:
((.setSvgString svgCanvas "string") (fn [data error]
(if error
;; handle error
;; handle data)))
Ah, ok. That makes sense. Thanks @renatoalencar.73
I'm glad to help