Fork me on GitHub
#clojurescript
<
2020-05-30
>
Eric Scott00:05:23

@lilactown, @noisesmith and @mfikes. The problem I describe above happened when I had separate clj and cljs files. It went away when I combined them into a single cljc file with lots of ugly reader conditionals in it.

Eric Scott00:05:28

Thanks for your help!

Shako Farhad00:05:56

Anyone know how to set JavaScript directives in ClojureScript? In the below docs it is shown to be used for some worklet API in re-animated v2. https://docs.swmansion.com/react-native-reanimated/docs/worklets I just have a hard time understanding how that looks in clojurescript. Anyone seen this before, or used something similar? 🙂

Tim05:05:56

Hi! What is directive? Is it this string in the source file like 'use strict' ?

Shako Farhad09:05:34

I believe so. I am not sure either. I am not really a javascript developer. But in the link it gives some examples of how it is written in javascript. @dnolen, hello David Nolen sir. Do you know how this can be accessed through clojurescript, sir?

raspasov02:05:01

@shakof91 that is a very good question; I really tried to find a way to set this but no luck… maybe someone else can chime in…

yubrshen05:05:55

Is there anyone who uses emacs (Doom) with Clojurescript and Shadow Cljs? I'm having trouble connecting to an already started Shadow cltjs server. When I did M-x cider-connect there are a few options, I'm not sure which to choose. I did get a REPL session, but the namespace is still cljs.user> not the expected my program's namespace. For example, there are two options related to shadow: shadow and shadow-select. With shadow selected, there are also options for builds: :app , :cards, :test, e2e, browser-repl, node-repl With :app selected, this what I got:

;; Connected to nREPL server - 
;; CIDER 0.25.0snapshot, nREPL 0.7.0
;; Clojure 1.10.1, Java 11.0.2
;;     Docs: (doc function-name)
;;           (find-doc part-of-name)
;;   Source: (source function-name)
;;  Javadoc: (javadoc java-object-or-class)
;;     Exit: <C-c C-q>
;;  Results: Stored in vars *1, *2, *3, an exception in *e;
;;
;; ClojureScript REPL type: shadow
;; ClojureScript REPL init form: (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :app) (shadow/nrepl-select :app))
;;
WARNING: CIDER requires cider-nrepl to be fully functional. Some features will not be available without it!
         More  quit, type: :cljs/quit
;; => [:selected :app]WARNING: clj-refactor and refactor-nrepl are out of sync.
Their versions are 2.5.0 and n/a, respectively.
You can mute this warning by changing cljr-suppress-middleware-warnings.
shadow.user> 
cljs.user> 
Now, I expect to go to my program's namesapce to be able to do evaluation in my program, the namespace of mine is defined in
(ns app.hello
  (:require [reagent.core :as r]))
Using C-c M-n M-n (`cider-set-ns`) doesn't work.

yubrshen06:05:08

I wonder what's the significance of my selected options: shadow vs. `shadow-select` :app , `:cards`, `:test`, `e2e`, `browser-repl`, `node-repl` I wonder if my selections are correct.

yubrshen06:05:10

Eventually, I found a work-around: Instead of cider-connect to the already started server, I can kill the started server and start from my emacs clojurescript file's buffer cider-jack-in for cljs, then with the same selections (`shadow`, :app) I was able to start the server and got a working repl that I can change the namespace to my program's. I can evaluate an expression in my source code buffer. I wish you can give me some pointers on how I can do better. Thanks in advance!

aisamu16:05:56

When you jack-in, cider injects all the relevant dependencies and middleware for you (which is what the REPL was complaining about). If you connect, you have to provide them yourself. Check the giant string that appears on the mini buffer when you jack in.

yubrshen18:05:43

I see that's why it's a lot harder to get connect working right.

yubrshen18:05:35

It seems that the reple to select should be shadow not shadow-select? Why?

sergey.shvets06:05:18

Hi, does anyone know a decent WYSIWYG editor that works well with ClojureScript? I tried to use Slate, but it fails with some very weird error when I try to edit content. Seems like closure compiler doesn't play well with that. Thanks in advance!

tianshu12:05:59

which library should I use if I want to have a ClojureScript interpreter in ClojureScript.

noisesmith14:06:31

I've enjoyed using lumo in the past https://github.com/anmonteiro/lumo - it runs on node

noisesmith14:06:55

there's another one that runs via platform specific system js interpreters (so instead of the portability of npm, you get the platform integration of your OS desktop environment) - planck https://planck-repl.org/

noisesmith14:06:17

both self host, you need to decide whether node vs. OS native has more advantages for your use case

noisesmith14:06:52

there might be something more recent / better maintained out there though

dnolen16:05:18

@shakof91 it's not possible to properly emit directives w/ ClojureScript

dnolen16:05:54

there's a implementation detail thing called js* which you can use, look at how the js-comment macro works

dnolen16:05:00

js* usage is strongly discouraged, but your only option at the moment - a enhancement ticket for a js-directive macro is also welcome

raspasov17:05:20

@dnolen thanks for the pointer

raspasov17:05:30

@shakof91 this might do it (needs to be in .cljc file that you require like

(:require-macros [my-project.macros :as macro])

raspasov17:05:44

(defmacro js-directive
  [directive]
  (list 'js* (str "'" directive "'")))

raspasov17:05:29

I haven’t tested with re-animated, but it seems to output the code when you print the function with (set! print-fn-bodies true)

raspasov17:05:18

(defn test-directive [x]
  (macro/js-directive "worklet")
  (+ 1 x))
rf.shared.main=> #object[rf$shared$main$test_directive “function rf$shared$main$test_directive(x){ ‘worklet’; return ((1) + x); }“]

Shako Farhad17:05:56

@dnolen, thank you for your answer! How or where do I make a ticket about this? I have never done such a thing. ^^ @raspasov thanks! That looks interesting. Hopefully it works with re-animated v2. The output surely suggests that it will work! I will save it. Thanks!

Shako Farhad18:05:55

@raspasov I have never created cljc files before. My folder structure is like this: app_name -> src -> cljs -> app_name -> cljs files Do I make a cljc folder and have a macros.cljc file with this content?

(ns app-name.macros)

(defmacro js-directive
          [directive]
          (list 'js* (str "'" directive "'")))
I am getting all kinds of warnings from intellij. SO probably not like this 😄 Edit: NVM, it was correct, but I needed to create the cljc folder within the cljs folder, or just have the macros.cljc in the cljs folder. It wasn't found when it was outside unfortunatly. Probably I have my filepaths and project structure setup wrong from the get go. Or I just need to rename the cljs folder to src or something. Not sure

raspasov18:05:48

Next to your cljs files should be fine, it doesn’t have to be in its own folder

raspasov18:05:32

the file needs to be named my-file.cljc

raspasov18:05:41

not my-file.cljs

Shako Farhad18:05:52

Alright good. I am not sure about these things. I thought maybe there was some convention surrounding these things 😄

raspasov18:05:13

let me know if it works

Shako Farhad18:05:19

Yes, I got it working. I look forward to re-animated v2. Even though I have gotten a lot done in v1. 😄

raspasov18:05:38

awesome, glad it works

didibus22:05:49

If a cljsjs package uses foreign-libs, that means it won't go through the Closure compiler correct?

Shako Farhad02:05:21

I am not quite sure about the :foreign-libs. If you have something like :infer-externs then maybe you are good, but usually you need to provide externs or use the foreign library with string names since the Closure compiler respects strings and doesnt munge them. But I am not sure about this. Hope it helps though!

thheller07:05:23

:foreign-libs are not processed in any way yes. they are just prepended to the final compilation output.