Fork me on GitHub
#clojurescript
<
2021-03-09
>
Clément Ronzon00:03:47

Hey gals and guys, Is there a library out there that would provide this kind of switch control (same behavior as a checkbox)?

p-himik00:03:53

If you're using React: https://material-ui.com/components/switches/ I'm sure there are many more other libraries that provide such an input.

Clément Ronzon14:03:16

Thank you guys, I'll look into that!

joelittlejohn17:03:07

I’m doing some work that involves introspection on ClojureScript constructs (vars, namespaces, etc). I’ve noticed that namespace docstrings do not appear to be available in ClojureScript-land in any way. The Namespace record includes a name and an internal ns object containing public vars, but there is no doc. Vars do have docs available to ClojureScript e.g. (-> myvar meta :doc). Anyone got any thoughts about why this is? Or maybe someone has a way to access these docstrings that I’m missing? I guess they’re simply not there because namespace docstrings are not expected to be needed by the deployed application and are expected to only be relevant during development or at the REPL. Would a PR to make these docstrings available be reasonable?

lilactown17:03:50

@joelittlejohn Clojure and ClojureScript are different in that CLJS does not reify vars and namespaces at runtime in your deployed application.

lilactown17:03:55

this information instead lives in the ClojureScript compiler

lilactown17:03:19

your intuition is correct in that the reason for this is to ensure that your app is slim and fast; emitting JavaScript code that added all of the namespace, var machinery and metadata would be at the least very costly in bundle size

lilactown17:03:20

the var macro is an explicit mark that reads the var metadata at compile time and emits it into your code

lilactown17:03:27

are you analyzing code on disk, or trying to build a live CLJS application that introspects itself?

joelittlejohn17:03:20

More the latter. I want to introspect on some cljs namespaces in my cljs app. It’s interesting that the var metadata is emitted but not the namespace metadata. So I can use ns-publics to get var info (and all metadata, including :doc), and I can use find-ns to get namespace info, it’s just that no doc field is present.

joelittlejohn17:03:19

I implemented a hack by creating my own macro to look up ns docstrings, and when the macro is compiled it emits all the relevant docstrings into its own source so they can be looked up later.

lilactown17:03:07

it looks like find-ns is bootstrap only: https://cljs.github.io/api/cljs.core/find-ns

lilactown17:03:31

so it's quite different than var and ns-publics which are macros that emit data from the analyzer

lilactown17:03:08

I think your approach is correct: create a macro that looks up the ns info at compile time and emit it

👌 1
joelittlejohn17:03:36

I suppose my next question would be: could we have a function, e.g. ns-meta that does exactly the same thing? (just like ns-publics, ns-imports, ns-interns)

joelittlejohn17:03:18

Well, I suppose we’re unlikely to start adding new cljs-specific introspection functions to the core for this.

lilactown17:03:17

yeah it might worth asking in #cljs-dev what the best way to do this is

👍 1