Fork me on GitHub
#clojurescript
<
2022-11-23
>
Chris McCormick09:11:13

Is there a way to access the JS equality operator == from cljs?

Chris McCormick09:11:37

I'm just trying to check a couple of booleans. 😅 (js-in test-value (j/obj actual-value true))

grav09:11:26

Well ... this works ... not sure if it's recommendable 🙂

(let [a 42
      b 43] 
    (js* "a == b"))

Chris McCormick09:11:03

Ah beautiful. That's got to be better than what I was doing.

Chris McCormick09:11:18

I wonder if those vars will survive advanced compilation though. thinking-face

grav09:11:33

Good call ... I'd say no 😄

grav09:11:58

Even :simple renames local vars as far as I remember.

grav10:11:27

But apart from that, I'm not sure from your example what you're trying to achieve - what does the j/obj part do?

Chris McCormick10:11:59

Ah sorry, that's applied-science.js-interop and it just creates a JavaScript native object like #js .

Chris McCormick10:11:28

What I am trying to achieve is miniscule build sizes using shadow-cljs for a small piece of front-end code. Will do a blog post about this.

Chris McCormick10:11:43

At the moment my build size is 640 bytes to add a little bit of on-page interaction. I still get to use cljs syntax and tooling like shadow-cljs live reloading.

grav10:11:46

Hm, still not quite following - where does the usage of the == operator come in? I assume you need the specific js-semantics in some way, like 42 == "42" evaluating to true?

Chris McCormick10:11:58

The problem is if you use Clojure's = operator the size of the build balloons out to 94kb.

Chris McCormick10:11:18

I would prefer to do a very simple equality check on two booleans and keep the build at 630 bytes.

👍 1
Hermann10:11:37

Sounds like a nice goal... but then it will behave like the JS == operator... ;)

grav10:11:03

I went hunting in the cljs source to see what happens in cljs.core/=. As far as I can see it calls out to identical? which calls itself? I'm not sure I understand that ...

1
Chris McCormick10:11:16

What would be good is js/== or js-equals. Maybe I should submit a PR. :thinking_face:

grav10:11:59

But how would that be implemented?

grav10:11:55

Which seems to use the js* == trick ... Since it's a macro, I assume it will then survive advanced compiling? :thinking_face:

grav10:11:12

Not sure how js* is implemented, but if it emits javascript before the Google Closure compiler is invoked, I'd expect everything to work

skylize13:11:26

Worth noting that you are probably looking for === and not ==. The == operator gives you automatic coercion semantics that probably have nothing to do with your described goal, while === tests for strict equality.

dvingo19:11:38

(coercive-= "" 0)
=> true
(coercive-= "" false)
=> true

😍 1
Chris McCormick00:11:13

@U051V5LLP ah thanks so much for this!

awesome 1
Tema Nomad10:11:41

Please help with understanding how to store/work with frontend routes if I have backend and frontend parts both in one place/repo? https://github.com/temanmd/clojure_learning_foobar I try to follow https://github.com/metosin/reitit/blob/master/doc/advanced/shared_routes.md Shared routes here https://github.com/temanmd/clojure_learning_foobar/blob/main/src/foobar/shared/routes.cljc Frontend routes here https://github.com/temanmd/clojure_learning_foobar/blob/main/src/foobar/frontend/app.cljs#L104 Backend routes here https://github.com/temanmd/clojure_learning_foobar/blob/main/src/foobar/backend/routes.clj All is work (link clicking changes URL in browser and render corresponding view, F5 reload works, all params on the place), BUT I dont know do I write it in proper way or not? And is it normal that I have to rewrite all frontend routes on backend part (why was "reitit shared routes" needed then?)?

grav17:11:34

Anyone using the AWS CDK javascript-version from ClojureScript? Seems everything is very much class-based, which makes me think that it's workable from ClojureScript with Shadow-Cljs's defclass ... but maybe it's a bad fit?

coltnz21:11:52

Thought about it, but Typescript is native for AWS, comes with code-completion etc which is very handy and CDK is really all about making objects so better suited.

👍 1
Joshua Suskalo19:11:03

Is there an overview anywhere that I can use when trying to implement a new data structure in CLJS that I can use as a reference for what to implement for someone familiar with the internals of writing data structures for JVM clojure?

Joshua Suskalo19:11:18

This is exactly what I was looking for.

awesome 1