Fork me on GitHub
#shadow-cljs
<
2019-09-20
>
Aklscc02:09:35

shadow-cljs compiles the RegExp has some problems, such as following code:

(let [v (js/RegExp. "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$")]
    (.test v p))
Then there is a compiler error:
main.cljs [line 55, col 54] Unsupported escape character: \d.

dpsutton03:09:25

seems its not shadow but cljs

dpsutton03:09:14

new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$").test("foo")
false

Aklscc05:09:58

Yes, RegExp seems doesn't work for this, but # does, please try it. And shadow-cljs can't compile "#" pattern too.

dpsutton03:09:21

but works in a js console

malch05:09:40

Hey, @thheller! I'm getting The shadow-cljs ClojureScript REPL is not available from CIDER with the new [email protected] Do I need to change something?

malch05:09:56

Looks like Cider expects shadow.repl to be present, was it changed?

malch07:09:42

Sorry, only now saw your comment in #cider channel simple_smile

thheller08:09:03

@malch I just released [email protected] which brings back that ns for cider. doesn't do anything but should fix the detection.

malch08:09:00

Thank you! I could've also created it myself simple_smile

Aklscc08:09:33

@thheller I'm sorry to bother you, but I have search much about RegExp in cljs. It looks like a compiler fault, which doesn't support some formats of the RegExp? 😂

thheller08:09:41

@180338742 the error you posted is the reader complaining. has nothing to do with regexp. you probably just need to escape the string properly?

thheller08:09:47

(let [v (js/RegExp. "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[^]{8,16}$")]
    (.test v p))

Saikyun10:09:24

hey @thheller I've made some progress with three.js + expo + shadow-cljs. I'm however experiencing some lag. it might be because I'm producing a lot of objects, but I also wanted to ask how much :compiler-options {:optimizations :advanced} affect this. when running shadow-cljs release app I had to set them to :simple in order to get the app to run. would this affect performance a lot?

Saikyun10:09:53

I've looked a bit at externs for three.js, and it seems possible to autogenerate them. however when I use :compiler-options {:infer-externs :all} I get some 400 warnings. it'd take some time to fix those, so I just wanted to ask beforehand if you knew if there'd be any significant performance (in terms of fps) gains, or if I should focus on other things (e.g. not creating as many objects per frame)

Saikyun10:09:09

I understand that this is a tricky question, so don't sweat it if it's too complex

Saikyun10:09:28

I think the performance is OK when building however (using `expo build:android), so maybe it doesn't matter that much

thheller11:09:14

@saikyun as the manual mentions, don't use :infer-externs :all. :auto is enough and all you can fix anyways.

thheller11:09:35

:advanced will be "smaller" so it'll probably load faster. runtime performance should be the same as :simple

Saikyun12:09:39

@thheller thanks for the info. :))

danielneal15:09:07

also make sure you do performance testing with expo dev set to off

danielneal15:09:29

I think in dev mode there’s a lot more things going on

deadghost17:09:19

If I'm requiring in ["@material-ui/core/styles" :refer [makeStyles]], what's the fully qualified name of makeStyles since @material-ui.core.styles/makeStyles will try to deref?

deadghost17:09:44

I'd like to use makeStyles in a macro

thheller17:09:59

can't easily access that from a macro currently

thheller17:09:45

you can use (cljs.analyzer/resolve-var &env 'makeStyles)

thheller17:09:03

or use a helper function which might be better depending on your use case

thheller17:09:25

(defn do-something [x] (makeStyles x)) and call do-something from the macro

deadghost18:09:22

yep the latter works fine

enn19:09:29

Is anyone successfully using CIDER with shadow-cljs? Every time I try to cider-jack-in-cljs I get a REPL which tells me: No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.

chepprey19:09:05

Try cider-connect-cljs instead of jack-in, emacs will ask you a few questions like host, port, and type (i don't have access to my cljs environ so I can't be specific)... you'll give it for ex localhost 8888 shadow and your shadow target code like dev or app or however you set it up

chepprey19:09:00

and make sure your browser is up and running & talking to your shadow command after you do the shadow-cljs watch [app]

enn20:09:33

@thheller how do I start the runtime if it's node, not the browser? @chepprey I've tried both ways, it does not seem able to connect when I enter the nREPL port number output by npx shadow-cljs server. There is no browser here, this is node.

thheller20:09:54

> 14.3.2. :target :node-script, :node-library These targets will have produced a .js file that are intended to run in a node process. Given the variety of options however you’ll need to run them yourself. For example a :node-script you’d run via node the-script.js and on startup it’ll try to connect to the shadow-cljs server. You should see a WebSocket connected message on startup. The output is designed to only run on the machine they were compiled on, don’t copy watch output to other machines.

thheller20:09:31

if you just need a node repl use shadow-cljs node-repl

thheller20:09:45

and connect to the :node-repl build. however that is done in cider I don't know

enn20:09:53

Hmm. It does not ask me for a build when I connect, only when I start from within CIDER with cider-jack-in.

enn20:09:46

and the REPL I get when I run cider-connect-cljs and put in the nrepl port number output when running shadow-cljs node-repl is a Java REPL

thheller20:09:25

it ALWAYS starts out as a clojure REPL

thheller20:09:31

you need to switch it to the REPL of the build you want

thheller20:09:43

I do not know the command in cider to do that

thheller20:09:00

I do not know if this is still current

thheller20:09:23

I don't know anything about cider and it seems to change constantly so no idea

mccraigmccraig20:09:09

@enn i use cider-connect-cljs then set the host and port then choose the cljs repl type as shadow-select then give the node-repl build

mccraigmccraig20:09:29

that puts me straight in a cljs repl

enn20:09:43

OK, that's good to know. After choosing shadow-select I get error in process filter: Wrong type argument: stringp, nil in the minibuffer, and I never get to choose a build. So likely I have some package version mismatch somewhere. The story of Emacs....

lilactown20:09:30

@enn your original problem was you need to run node path/to/output/script.js

thanks3 4
lilactown20:09:06

to do a plain node-repl in Emacs (basically, a CLJS REPL without an associated build) I do: 1. cider-jack-in which lands me in a CLJ REPL 2. (shadow/node-repl) which lands me in a CLJS REPL where I don’t need to start an external process like node path/to/build/output.js or a browser window

lilactown20:09:39

from there i can also type :cljs/quit to go back to the CLJ REPL and start/stop/REPL in to my other builds

lilactown20:09:12

in other news, I’m attempting to transition a lein-figwheel project to shadow-cljs and it is rough

lilactown20:09:47

lots of cljsjs I have to proxy myself, several of which don’t have exact same versions on npm… shadow-cljs actually using the core specs on our bad code… etc. 😛

😎 4
lilactown21:09:35

I’m running into a real weird spec error

lilactown21:09:12

the code:

(condp = tag
  ...
      :clojure.spec.alpha/invalid
      (throw (ex-info
               "Visual Segment Value Was Invalid"
               {:value value
                :explain-data (spec/explain-data :visual-segment/value value)})))

lilactown21:09:41

the error:

478 |     (condp = tag
-----------^--------------------------------------------------------------------
Syntax error macroexpanding cljs.core/let.
Call to cljs.core/let did not conform to spec.
-- Spec failed --------------------

  ([... :clojure.spec.alpha/invalid ... ...] ...)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^

should satisfy

  any?

-- Relevant specs -------

:shadow.cljs.devtools.cljs-specs/bindings:
  (clojure.spec.alpha/and
   clojure.core/vector?
   shadow.cljs.devtools.cljs-specs/even-number-of-forms?
   (clojure.spec.alpha/* :shadow.cljs.devtools.cljs-specs/binding))

-------------------------
Detected 1 error

lilactown21:09:11

changing clojure.spec.alpha/invalid to anything else alleviates the error 😵

thheller21:09:23

do you have something reproducible? (condp = tag :clojure.spec/invalid :foo) works fine

thheller21:09:39

(condp = :clojure.spec.alpha/invalid :foo :bar) this fails with the error?

thheller21:09:46

fails in clojure too though

thheller22:09:43

hmm (let [x :clojure.spec.alpha/invalid] x)

thheller22:09:54

seems like a bug 😛

thheller22:09:41

@lilactown workaround: (def INVALID :clojure.spec.alpha/invalid) and then use INVALID in the condp

lilactown22:09:56

that works! thx

thheller22:09:10

name is of course up to you 😉

lilactown22:09:07

(def blame-alex-miller ...)