Fork me on GitHub
#clojurescript
<
2021-12-29
>
West00:12:30

Is there an easy way to convert a javascript regex pattern to a pattern that will work in clojurescript source? Or do I just have to escape characters individually?

Thomas Meier03:12:01

keep running in circles with interop trying to turn this: data = event.dataTransfer.getData("text") into this (event is %) (let [data (. % .-dataTransfer -getData "text")]) and various other combinations with different errors each time

seancorfield03:12:01

(let [data (.getData (.-dataTransfer %) "text")] ...)

seancorfield03:12:30

I think you want .. if you want to "thread" things: (.. % -dataTransfer (getData "text")) off the top of my head.

seancorfield03:12:24

Q re: Windows/WSL -- is anyone doing cljs development on Windows with the ClojureScript processes running on WSL2? When I run this command on WSL2, I get a Google Chrome instance running, displaying the cljs welcome page, but I never get an actual REPL prompt:

clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "RELEASE"}}}' -M -m cljs.main -r
If I then close the browser, the version and REPL prompt appears but of course errors out due to losing the connection to the browser:
ClojureScript 1.11.4
cljs.user=> Execution error (SocketException) at sun.nio.ch.NioSocketImpl/implWrite (NioSocketImpl.java:420).
Broken pipe

Full report at:
/tmp/clojure-11840304026226495887.edn

seancorfield03:12:14

That EDN file starts with

{:clojure.main/message
 "Execution error (SocketException) at sun.nio.ch.NioSocketImpl/implWrite (NioSocketImpl.java:420).\nBroken pipe\n",
 :clojure.main/triage
 {:clojure.error/class java.net.SocketException,
  :clojure.error/line 420,
  :clojure.error/cause "Broken pipe",
  :clojure.error/symbol sun.nio.ch.NioSocketImpl/implWrite,
  :clojure.error/source "NioSocketImpl.java",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.ExceptionInfo,
    :message "Unexpected error during REPL initialization",
    :data {:cljs.repl/error :init-failed},
    :at [cljs.repl$repl_STAR_ invokeStatic "repl.cljc" 1220]}
   {:type java.net.SocketException,
    :message "Broken pipe",
    :at
    [sun.nio.ch.NioSocketImpl implWrite "NioSocketImpl.java" 420]}],
  :trace
  [[sun.nio.ch.NioSocketImpl implWrite "NioSocketImpl.java" 420]
   [sun.nio.ch.NioSocketImpl write "NioSocketImpl.java" 440]
   [sun.nio.ch.NioSocketImpl$2 write "NioSocketImpl.java" 826]
   [java.net.Socket$SocketOutputStream write "Socket.java" 1035]
   [jdk.internal.reflect.GeneratedMethodAccessor10 invoke nil -1]
   [jdk.internal.reflect.DelegatingMethodAccessorImpl
    invoke
    "DelegatingMethodAccessorImpl.java"
    43]
   [java.lang.reflect.Method invoke "Method.java" 568]
   [clojure.lang.Reflector invokeMatchingMethod "Reflector.java" 167]
   [clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 102]
   [cljs.repl.server$send_and_close invokeStatic "server.clj" 168]

Nechemya Ungar07:12:29

Maybe an idea to sidestep the problem could be to install chrome on the wsl2 itself? :thinking_face: https://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps#install-google-chrome-for-linux

naomarik09:12:47

i've been doing dev on wsl2 for quite awhile now, i use shadow-cljs though and i'm able to connect to a repl just fine using any browser on windows side

naomarik09:12:20

i'll typically connect to a clj repl first then use cider-connect-sibling-cljs

brendnz10:12:55

"Start the REPL using the pattern described above, but with the browser as the evaluation environment.

(require '[cljs.repl :as repl])
(require '[cljs.repl.browser :as browser])  ;; require the browser implementation of IJavaScriptEnv
(def env (browser/repl-env)) ;; create a new environment
(repl/repl env) ;; start the REPL
Once the REPL has started, you will see the message "Starting server on port 9000". At this point, open the html page by going to http://localhost:9000 to complete the connection. Once the page is open and the connection is made, the REPL prompt will be displayed." [Edit] Um, so what does it mean "but with the browser as the evaluation environment"? I'm afraid I had assumed this was the process to create a browser cljs repl from say clj (this is what I thought cljs meant in the namespace), but this may be code to create ANOTHER browser repl from a browser repl. Before seeing Sean's post I was going to take a couple of weeks to read some source code behind this problem after having queried pez on #calva. I still have to take the time to read it, but I wanted to put my two cents in before then.

brendnz10:12:09

Forgot to press "shift enter" again. I will complete what I was going to write shortly. The above is from https://clojurescript.org/reference/repl . It will fail at (repl/repl env) in WSL2 because of a socket not being released prior to an attempt to make a connection (I think). I am going to collect screenshots. I believe it is a Linux thing in general and not a WSL2 thing in particular, because https://clojurescript.org/guides/quick-start says: "If you are running Linux and the REPL does not start, try disabling browser auto-launch and opening `http://localhost:9000` manually:" The article does not say WHY some Linux setups won't work properly, but I believe it is the same issue.

brendnz11:12:55

The purpose of this next screenshot is to show the browser window opened, although I have just said that already. I hesitate highlight the ?rel=1640775390178 part, because it is undoubtedly not relevant, but does anyone know what it means?

brendnz11:12:29

"Fire up the Clojurescript Quick Browser REPL" in Calva and the same thing happens. The browser repl opens in a browser window, but it is inaccessible to the editor. Incidentally, I have until yesterday thought the browser REPL was a process or sub-process within the browser instance. It may still be, but something I read yesterday talked in terms of the browser being a separate process serving a/the browser REPL. Anyway, Calva presents us with the following screen. It says "Connecting cljs repl:", but it never does; it gets stuck here just like repl/repl got stuck in the clj repl above. I understand a cljs prompt is meant to appear after this, but I have never seen one on my system.

brendnz11:12:26

When I close the browser window, Calva prints out additional lines 22-27: A SocketException; Write failed because of a broken pipe. Calva then evaluates core.cljs (in package hello_world), but in nrepl, not the browser repl that we want.

brendnz11:12:48

I will refer to this screenshot next, as the Slack appears to always present the graphics at the end of each comment in the thread.

brendnz11:12:29

The above nREPL log does not record an error (though nrepl does reply with a repl type of clj when I would expect cljs), but cider.piggieback/cljs-repl returns the following error when repeated in the editor (because, I presume the http server is holding onto a broken pipe making its socket unavailable):     Execution error (BindException) at http://java.net.PlainSocketImpl/socketBind (PlainSocketImpl.java:-2).     Address already in use (Bind failed)

brendnz11:12:02

That's me for the moment. Good luck.

seancorfield17:12:18

This was the magic piece I had missed: > "If you are running Linux and the REPL does not start, try disabling browser auto-launch and opening http://localhost:9000 manually:" Thanks @brendnz! If I start the basic REPL with --repl-opts '{:launch-browser false}' and then visit http://localhost:9000 in either Google Chrome on Linux or Edge on Windows, it all works as expected.

Mutasem Hidmi13:12:38

Hi guys. I am new to Clojure and clojurescript. What is the best way to use npm packages in clojurescript? I was searching for how to do a wrapper around an npm package, but I didn't find a very useful resource for that. I found many packages under the cljsjs link https://cljsjs.github.io/, but I also want to be able to build my own wrapper. I appreciate your help.

Arthur13:12:10

You can try using shadow-cljs. You can then require most of the npm libraries you have installed in your project doing something like (:require ["react" :as react])

Mutasem Hidmi13:12:52

Thanks Arthur. Does that have a downside on the performance?

Jon Boone14:12:53

What is the baseline against which you want to compare using shadow-cljs?

☝️ 1
naomarik15:12:57

What do you guys recommend to use for clojure/script time with time zone support? I can see juxt tick as being a good candidate, any other recommendations?

emccue15:12:16

cljc-java-time

👆 1
emccue15:12:34

tick is built on it, but its less of a “innovative” api

Ben Sless17:12:54

If I want to extend a protocol to the types for which the predicates map?, set? and sequential? are true, which types would they be in cljs?

seancorfield17:12:10

According to a cljs REPL, map? is satisfies? IMap, set? is ISet, and sequential? is ISequential. (based on calling source on each of these)

seancorfield17:12:02

(so you'll need to extend those protocols to whatever your new thing is)

Ben Sless17:12:57

It's for a walking protocol, so I won't need to extend them, but every type which implements them 😞

seancorfield17:12:14

I suspected as much. Sorry.

Ben Sless17:12:29

Can you extend protocols to protocols on cljs or is it the same problem as in clj?

seancorfield17:12:51

No idea. My knowledge of cljs and its differences from clj is minimal.

👍 1
Ben Sless18:12:43

Lol, seems like Ethan's solution is the way to go then.

Lone Ranger22:12:02

This is killing me:

Use of undeclared Var cljs.core.async.interop/p->c
Anybody seen this before?

Lone Ranger22:12:25

to answer my own question, <p! needs to be in :require not :require-macros