clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2021-03-01T13:28:21.130400Z

I would like to make a text-area that I can insert clojure code and it'll be formatted.

2021-03-01T13:28:59.131400Z

how can I force formatting-like features, like a text area to insert code, I know there's a lib for doing this

2021-03-01T13:29:17.132Z

but I don't know the name / means to find it

Schpaa 2021-03-01T13:29:50.132300Z

Zprint?

2021-03-01T13:30:18.132500Z

not only to print

2021-03-01T13:30:31.133100Z

but format the input when you're inputting something

Schpaa 2021-03-01T13:30:43.133500Z

Just the first thing that came to my mind...

p-himik 2021-03-01T13:31:57.133800Z

@d.ian.b zprint is a library - you can call it to format any string.

p-himik 2021-03-01T13:32:45.133900Z

Examples: https://github.com/kkinnear/zprint/blob/master/doc/using/library.md

2021-03-01T13:35:53.134500Z

https://blog.wsscode.com/pathom/v2/pathom/2.2.0/introduction.html => like in this box to make queries

2021-03-01T13:36:18.135100Z

to have parinfer-like completions and these stuff

2021-03-02T15:38:45.146600Z

do you have some tips on how to use with reagent?

2021-03-02T15:39:46.146800Z

to swap! a state and insert the source in a atom

flowthing 2021-03-02T17:27:34.148700Z

Sorry, no. I haven’t used it myself.

2021-03-02T18:14:22.149200Z

I found this to be very hacky 😞

flowthing 2021-03-01T13:39:59.135300Z

You're probably looking for something like this: https://nextjournal.github.io/clojure-mode/

1
2021-03-01T13:43:33.135600Z

thanks!

2021-03-01T15:45:40.137300Z

I've been having a discussion on the pros and cons of goog.object/get vs dotted access for js APIs, which I've tried to summarise here: https://widdindustries.com/clojurescript-jsinterop/ I'd be interested to hear anyone's thoughts

raspasov 2021-03-02T09:55:49.143300Z

@thheller that’s actually a very good point re: the whole code base through Google Closure possibility (however unlikely it may be)

raspasov 2021-03-02T09:56:17.143500Z

I just switched all my interop calls to dot syntax 🙂

raspasov 2021-03-01T16:12:56.137500Z

My 2 cents: in the interest of avoiding extra dependencies, I’ve opted against adding extra libs that do interop… perhaps if I’m doing interop I want the code to be ugly and for the code to stand out (sort of like a “here be dragons” sign 🙂 ) … So I think I agree with David Nolen but don’t have a super strong opinion on all the possible combinations of data vs. methods; JS land can be pretty hopeless in that regard, so I don’t think we can make a blanket statement what’s what (like you point out) for myself, I’ve done two very basic functions over goog closure: https://github.com/raspasov/alexandria-clj/blob/main/src/ax/cljs/googc.cljs

2021-03-01T16:24:15.138Z

Thanks. yeah I think I've taken various different approaches over time and I've come to think the main thing really is to try to aim for some consistency

👍 1
thheller 2021-03-01T16:48:23.138300Z

I think it is worth mentioning why we care about this from the closure-compiler perspective. first noting what it compiles down to after :advanced. (.-foo obj) just results in obj.foo while (gobj/get obj "foo") results in obj["foo"] or even obj.foo if property is known and valid name at compile time. (`:advanced` removes goog.object operations). then following https://developers.google.com/closure/compiler/docs/api-tutorial3#propnames

thheller 2021-03-01T16:50:09.138700Z

note that this is also relevant in cases where it ever becomes practical that the WHOLE code can be :advanced compiled. that is including all dependencies from npm as well. then gobj/get uses for code would break because those would not have been renamed

thheller 2021-03-01T16:51:12.139Z

^js hints are only required because not all code is going through :advanced. so if that ever becomes practical you wouldn't need those either.

thheller 2021-03-01T16:56:40.139600Z

so as David said. dot access for code, goog.object for data (eg. JSON)

2
2021-03-01T17:02:18.139800Z

thanks that's a good point against "gobj/get is safer bc no need to get type hints correct" => it's actually not safer bc it may break in future with smarter compilation

thheller 2021-03-01T17:07:17.140Z

not sure we'll ever get to that place but yeah

isak 2021-03-01T21:06:56.140300Z

Related, https://developers.google.com/closure/compiler/docs/api-tutorial3#propnames: > Inconsistent Property Names > Closure Compiler compilation never changes string literals in your code, no matter what compilation level you use. This means that compilation with ADVANCED_OPTIMIZATIONS treats properties differently depending on whether your code accesses them with a string. If you mix string references to a property with dot-syntax references, Closure Compiler renames some of the references to that property but not others. As a result, your code will probably not run correctly. I think this means if you are doing something different from even the other closure-friendly libraries you depend on (e.g., re-frame), you might get wrecked. No?

p-himik 2021-03-01T21:39:28.140700Z

If you start using JS interop to talk with CLJS then yes, I think. If you stay within CLJS, then no.

isak 2021-03-01T21:51:34.141200Z

@p-himik You're probably right, though I think there can be some good reasons to do that sometimes, like perf. Also do you know if record property access is made consistent somehow if you access them in different ways? E.g., (.-myProp my-record) vs (:myProp my-record)

p-himik 2021-03-01T22:18:56.141400Z

AFAIK all properties that have the same name will be renamed to the same name as well. So if you use (.-myProp my-record) without adding ^js, myProp will be renamed consistently - both at the point of invocation and at the point of record definition.

p-himik 2021-03-01T22:19:24.141600Z

And keyword record access turns into JS field access anyway.

isak 2021-03-01T22:43:59.141800Z

Ok, right. Just realized also I was thinking about that wrong, because it actually doesn't matter if the prop name happens to match the key name in the minified js output, since the 2 ways of access would go via different mechanisms. (Normal js prop vs whatever the protocol access compiles to, maybe calling a function with a switch).

isak 2021-03-01T22:44:51.142Z

> And keyword record access turns into JS field access anyway. Ok good to know, though I'm sure it is only if the key can be determined statically

p-himik 2021-03-01T22:49:03.142300Z

(let [k :myProp] (k my-record)) will also result in a JS field access. All keyword lookups on records turn into a function call that does switch over (name k).

isak 2021-03-01T22:54:51.142500Z

By non-static I was thinking more like this:

(def props (->> [:foo :bar :baz] shuffle (take 2)))
  
(doseq [p props]
  (println p (p x)))

isak 2021-03-01T22:55:20.142700Z

> All keyword lookups on records turn into a function call that does `switch` over `(name k)` 👍:skin-tone-2: