Fork me on GitHub

I'd like to create a diagramming tool in cljs with a datascript backing. reagent producing svg seems like the obvious place to start. Any prior art I should look at? More details: I'm trying to write a home wiring diagramming tool on steroids: imagine switches, cabling, etc 🙂


(I appreciate that there's a commercial datascript-backed project that does this for datacenters)


is there any good way to make components that have [& args]? I want to design my components so that they follow the hiccup convention of being able to do either

 [button-component "sign up"]
 [button-component "log in"]
 [button-component "about"]]
 (for [label ["sign up" "log in" "about"]]
   [button-component label])]


I guess you'd have to manually check whether args has a list in its list?


oh... you know actually I'm cool with just

(into [nav-component]
    (for [name ["hey" "check" "these" "buttons"]]
        [button-component name]))


which apparently works


In ClJS, Is there a way to programmatically get the value of a symbol? Since there are no vars I think the answer to this is probably 'no'. Looking around seems to indicate this is correct - can't find anything that would do the job. I can think of a way to cheat to achieve the same thing (fixed, limited number of such symbols), but if there really is a way out of the box...


@jsa-aerial If :advanced is being used, then there’s not much you can do. On the other extreme, self-hosted ClojureScript is closer to Clojure with respect to runtime behavior.


Depending on what you are really doing, you might be able to get away with code like

cljs.user=> (def a 3)
cljs.user=> @(resolve 'a)


@mfikes Thanks - figured as much. I think the simplest is to just create my own lookup table. I'm lucky enough that there is a fixed up front known set of symbols that I need this for, so I can just create a simple map...


Cool. And FWIW, symbols work like keywords in that they can look themselves up in a map.


Right - the map is entries of the form [sym symval] where this is created from a quoted list of the syms and a list of the syms.


Seems to be working fine - thanks to #specter again as well!


If it turns out that your symbols are associated with the public vars in a given namespace, ns-publics could be useful. Otherwise, building a fixed-size map sounds like the right solutions.


@mfikes Actually, that could be useful - many thanks!


No problem… I’ve written some code like that, and since you are given the vars, you can even filter that map down to a submap that only has entries where the vars have some custom meta on them. For example, (def ^:included a 3)


@mfikes Yeah - wow, that looks basically like the exact solution, thanks again!


This could be useful when exposing certain functions in a namespace for external invocation, or other such things. The nice thing is that it boils down to you simply adding some meta on the vars you want included.


The negative aspect is that it ends up creating a bit of var bloat in the JavaScript, but it is a tradeoff.


Hmmm, I need the value not the var - since the vars are gone at runtime - or is there a way to get the value from the var at comp time?


Oh - this is a 'special way' to get vars at runtime?


If the vars are associated functions, you can just use them directly. But if the vars are somethings else (like numbers), then you can deref them.


Here is an example of those ideas:

cljs.user=> (defn foo [x] (inc x))
cljs.user=> (#'cljs.user/foo 3)
cljs.user=> (def bar 10)
cljs.user=> @#'cljs.user/bar


The vars are not completely gone at runtime.


Ahh - so these vars work more or less like real Clojure vars?


In a lot of static ways, they work like real Clojure vars.

✔️ 1

Given this info - I think ns-publics gives the required xref map without need of 'manually' constructing it. This is all really useful - @mfikes thanks for all this great info.

👍 1