This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-01
Channels
- # aws (7)
- # bangalore-clj (10)
- # beginners (27)
- # braveandtrue (4)
- # calva (2)
- # cider (9)
- # cljs-dev (20)
- # clojure (228)
- # clojure-germany (5)
- # clojure-spec (7)
- # clojurescript (32)
- # datomic (11)
- # figwheel-main (10)
- # fulcro (21)
- # hyperfiddle (3)
- # off-topic (53)
- # onyx (1)
- # portkey (2)
- # re-frame (21)
- # reagent (1)
- # shadow-cljs (5)
- # spacemacs (7)
- # specter (4)
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
[nav-component
[button-component "sign up"]
[button-component "log in"]
[button-component "about"]]
or
[nav-component
(for [label ["sign up" "log in" "about"]]
[button-component label])]
oh... you know actually I'm cool with just
(into [nav-component]
(for [name ["hey" "check" "these" "buttons"]]
[button-component name]))
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/a
cljs.user=> @(resolve 'a)
3
@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!
@jsa-aerial Cool. Here is a gist of the idea: https://gist.github.com/mfikes/c16b0bae583127d6b84754c48106563c
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/foo
cljs.user=> (#'cljs.user/foo 3)
4
cljs.user=> (def bar 10)
#'cljs.user/bar
cljs.user=> @#'cljs.user/bar
10
Ahh - so these vars work more or less like real Clojure vars?
Here is a bit of writeup on that https://stackoverflow.com/questions/50201703/how-do-i-extract-metadata-from-a-var-when-a-function-returns-its-symbol/50205987#50205987
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.