Hi all, I鈥檓 in the process of learning clojure and clojurescript, as part of that I鈥檓 implementing tetris https://github.com/alamqadem/tetris-clj.
So far, I鈥檝e set up a clojure project with lein and I am able to play it in a terminal.
Now, I would like to reuse the same code for a cljs project and have the graphical interface in the browser, but keep at the same time also the ability to run it in the terminal.
Would it be possible for the same project to be a clojure project and cljs project?
Btw, if you have a beginner guide on how to get started with cljs and set up a repl, I would really appreciate it.
> Would it be possible for the same project to be a clojure project and cljs project?
Yes. of course.
Everything that's common can be put in .cljc files - those are read by both CLJ and CLJS.
Everything that differs can be either put in their own .clj/`.cljs` files or inside so-called reader conditionals in .cljc files.
What editor are you using? Do you have a specific question about the repl/are you encountering a particular issue? Here is the cider manual if you are using emacs https://docs.cider.mx/cider/1.17/ https://www.youtube.com/watch?v=aYA4AAjLfT0 Hopefully one of these videos might be helpful: https://www.youtube.com/watch?v=gIoadGfm5T8 https://www.youtube.com/watch?v=7muHVkxzZcE https://www.youtube.com/watch?v=VbIawuoYAVY https://www.youtube.com/results?search_query=clojurescript+sets
What is the effect of adding ^js to destructuring? For example (fn [{:keys [^js foo ^js bar]}] ,,,)
Should be the same as if you introduced a symbol like (let [^js foo (get args :foo)] ...).
And what is the effect of that...? I haven't quite grasped the purpose of ^js
https://shadow-cljs.github.io/docs/UsersGuide.html#infer-externs
Same but in the vanilla CLJS docs: https://clojurescript.org/guides/externs#externs-inference
Note that ^js/Something is functionally fully equivalent to just ^js.
This is from code that I haven't written myself. But I have full control over the :foo and :bar keys and the argument is a regular cljs map. So is there any need for ^js?
The values for these keys are DOM elements
For DOM elements there should be no need for ^js unless, I think, the CLJS function uses some very new DOM API that's not a part of the built-in externs.
But ^js also won't hurt here and might serve as documentation of sorts.
Thanks!
Still trying to grasp this. I assume that keywords are never renamed? So the interpretation is that in (.field foo), .field will not be renamed? foo from the original example.
Yes.
Get it!