clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Clément Ronzon 2021-03-09T00:14:47.251300Z

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

Clément Ronzon 2021-03-09T14:36:16.259100Z

Thank you guys, I'll look into that!

p-himik 2021-03-09T00:25:53.251400Z

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.

jeffmk 2021-03-09T05:39:34.251800Z

@clement.ronzon Spectre.css can do that with (I think) just CSS: https://picturepan2.github.io/spectre/elements/forms.html#forms-switch

joelittlejohn 2021-03-09T17:15:07.260500Z

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?

lilactown 2021-03-09T17:18:50.261300Z

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

lilactown 2021-03-09T17:19:55.262400Z

this information instead lives in the ClojureScript compiler

lilactown 2021-03-09T17:21:19.263900Z

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

lilactown 2021-03-09T17:22:20.264900Z

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

lilactown 2021-03-09T17:23:27.265400Z

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

joelittlejohn 2021-03-09T17:30:20.268300Z

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.

joelittlejohn 2021-03-09T17:32:19.269700Z

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.

lilactown 2021-03-09T17:35:00.270300Z

hmmm

lilactown 2021-03-09T17:35:07.270600Z

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

lilactown 2021-03-09T17:35:31.271100Z

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

lilactown 2021-03-09T17:36:08.271700Z

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

👌 1
joelittlejohn 2021-03-09T17:41:36.273200Z

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)

joelittlejohn 2021-03-09T17:44:18.275Z

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

lilactown 2021-03-09T17:45:17.275500Z

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

👍 1