Fork me on GitHub
#clojurescript
<
2020-03-01
>
deep-symmetry01:03:10

Hey! I’m a Clojurist who is about to dive into Clojurescript in a bit of a weird way, and I just realized I could probably save a ton of time by asking questions here rather than googling like mad for something approaching my use case.

deep-symmetry01:03:35

The context is that I am collaborating with someone to build an Asciidoctor extension that will allow me (and others) to create diagrams like this: https://deepsymmetry.org/images/test.svg

deep-symmetry01:03:38

I have that working great in Clojure, and now I need to port it to ClojureScript so that it can work in the node environment that hosts Asciidoctor extensions. So my basic question is, is there an example somewhere of using ClojureScript to create a JavaScript function to be called by other JS code? I have only seen examples going the other direction.

deep-symmetry01:03:38

I have to say I’m delighted at how much of the Clojure language I’ve been able to provide access to through a safe EDN parser which requires no run-time compilation in an evening and afternoon! If anyone is curious, the Clojure implementation I am going to try to port to ClojureScript is here: https://github.com/Deep-Symmetry/dysentery/blob/master/src/dysentery/edn_diagram.clj

deep-symmetry01:03:47

Ah! This looks promising! But I would definitely welcome more tips, thoughts and pointers: https://lambdaisland.com/blog/2017-05-02-nodejs-scripts-clojurescript

coby04:03:31

I skimmed that article and it looks pretty good! I like all of lambdaisland's stuff that I've read. For tooling, I'd recommend you check out the shadow-cljs compiler instead of vanilla Leiningen. It's much nicer for JS interop, IMO. Haven't used this feature but the :npm-module target seems particularly suited to your use case: https://shadow-cljs.github.io/docs/UsersGuide.html#target-npm-module

coby04:03:46

shadow-cljs also lets you manage your JS deps with a regular ol' package.json, so if there's specific stuff from the Node ecoystem you want to integrate with/expose, it makes that really easy. Check out the #shadow-cljs room, Thomas (the author) hangs out there and typically responds quickly. :)

deep-symmetry05:03:09

Ooh, thank you! I got the basic “hello world” example working with Leiningen (and that is the world I am much more familiar with) and quickly stepped on a rake that someone else had as well. I have heard several people rave about shadow-cljs, and this link makes it look quite compelling. I will change gears and try that!

darwin17:03:02

I’ve done something pretty crazy over the weekend. I got working cljs REPL inside Blender: https://box.binaryage.com/shadow-cljs-blender-repl.png Note that Blender does not support javascript. Blender embeds Python engine and exposes its API for (interactive) python scripting. I ended up embedding V8 into Python and implementing bare minimum of DOM apis to get shadow-cljs :browser target working, including repl interaction. It is highly experimental at this point, but in general with this approach we can bring cljs anywhere where V8 can be embedded…

💯 28
8
👀 12
aw_yeah 8
knubie18:03:50

If i have a symbol like (symbol "my-ns" "foobar"), how can I then resolve the value?

thheller18:03:52

in CLJS you cannot

thheller18:03:32

in development you can in theory but not after :advanced