Fork me on GitHub
#clojurescript
<
2021-03-01
>
Ian Fernandez13:03:21

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

Ian Fernandez13:03:59

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

Ian Fernandez13:03:17

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

Ian Fernandez13:03:18

not only to print

Ian Fernandez13:03:31

but format the input when you're inputting something

Schpaa13:03:43

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

p-himik13:03:57

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

Ian Fernandez13:03:18

to have parinfer-like completions and these stuff

flowthing13:03:59

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

clojure-spin 3
Ian Fernandez15:03:45

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

Ian Fernandez15:03:46

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

flowthing17:03:34

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

Ian Fernandez18:03:22

I found this to be very hacky 😞

henryw37415:03:40

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

raspasov16:03:56

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

henryw37416:03:15

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

👍 3
thheller16:03:23

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

thheller16:03:09

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

thheller16:03:12

^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.

thheller16:03:40

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

6
henryw37417:03:18

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

thheller17:03:17

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

isak21:03:56

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-himik21:03:28

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

isak21:03:34

@U2FRKM4TW 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-himik22:03:56

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-himik22:03:24

And keyword record access turns into JS field access anyway.

isak22:03:59

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).

isak22:03:51

> 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-himik22:03:03

(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).

isak22:03:51

By non-static I was thinking more like this:

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

isak22:03:20

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

raspasov09:03:49

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

raspasov09:03:17

I just switched all my interop calls to dot syntax 🙂