This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-23
Channels
- # announcements (26)
- # babashka (8)
- # babashka-sci-dev (3)
- # beginners (93)
- # biff (44)
- # calva (1)
- # cider (7)
- # clj-kondo (13)
- # cljdoc (1)
- # clojure (121)
- # clojure-australia (2)
- # clojure-europe (18)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (1)
- # clojurescript (35)
- # conjure (1)
- # core-async (2)
- # datalevin (6)
- # datomic (28)
- # emacs (25)
- # events (1)
- # fulcro (5)
- # introduce-yourself (2)
- # jobs (8)
- # leiningen (2)
- # off-topic (13)
- # other-languages (1)
- # podcasts-discuss (1)
- # polylith (7)
- # rdf (6)
- # re-frame (1)
- # reagent (53)
- # releases (3)
- # rewrite-clj (7)
- # scittle (5)
- # shadow-cljs (63)
- # specter (1)
- # squint (5)
- # tools-build (5)
- # xtdb (7)
Is there a way to access the JS equality operator ==
from cljs?
I'm just trying to check a couple of booleans. 😅
(js-in test-value (j/obj actual-value true))
Well ... this works ... not sure if it's recommendable 🙂
(let [a 42
b 43]
(js* "a == b"))
Ah beautiful. That's got to be better than what I was doing.
I wonder if those vars will survive advanced compilation though.
But apart from that, I'm not sure from your example what you're trying to achieve - what does the j/obj
part do?
Ah sorry, that's applied-science.js-interop
and it just creates a JavaScript native object like #js
.
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.
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.
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
?
The problem is if you use Clojure's =
operator the size of the build balloons out to 94kb.
I would prefer to do a very simple equality check on two booleans and keep the build at 630 bytes.
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 ...
What would be good is js/==
or js-equals
. Maybe I should submit a PR. :thinking_face:
Ah, identical?
the function calls identical?
the macro:
https://github.com/clojure/clojurescript/blob/9359f40e7537307b9272fd322ae5cfff88e079f2/src/main/clojure/cljs/core.cljc#L998
Which seems to use the js* ==
trick ...
Since it's a macro, I assume it will then survive advanced compiling? :thinking_face:
Not sure how js*
is implemented, but if it emits javascript before the Google Closure compiler is invoked, I'd expect everything to work
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.
if you do want coercive equality (`==`) looks like cljs.core has you covered https://github.com/clojure/clojurescript/blob/9359f40e7537307b9272fd322ae5cfff88e079f2/src/main/clojure/cljs/core.cljc#L911
the js*
form is handled in the analyzer here https://github.com/clojure/clojurescript/blob/9359f40e7537307b9272fd322ae5cfff88e079f2/src/main/clojure/cljs/analyzer.cljc#L3694
and emitted in the "compiler" here
https://github.com/clojure/clojurescript/blob/9359f40e7537307b9272fd322ae5cfff88e079f2/src/main/clojure/cljs/compiler.cljc#L1434
pretty straightforward pass-through to the output js
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?)?
finally I solved the problem: https://github.com/temanmd/clojure_learning_foobar/blob/main/src/foobar/backend/routes.clj#L17
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?
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.
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?
this awesome book should help with that https://funcool.github.io/clojurescript-unraveled/#core-protocols-section
Thanks!