This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-29
Channels
- # admin-announcements (1)
- # announcements (3)
- # babashka (18)
- # beginners (35)
- # cider (4)
- # clj-kondo (52)
- # cljs-dev (2)
- # clojure (92)
- # clojure-spec (18)
- # clojurescript (17)
- # conjure (11)
- # core-async (1)
- # datomic (11)
- # emacs (5)
- # fulcro (11)
- # graalvm (10)
- # helix (21)
- # kaocha (6)
- # malli (1)
- # membrane (37)
- # off-topic (110)
- # re-frame (1)
- # reagent (12)
- # reitit (5)
- # rewrite-clj (1)
- # sci (1)
- # shadow-cljs (40)
- # vim (21)
- # vrac (17)
I didn’t really know the right forum, so I’m posting in a couple of cljs-related channels. There’s more information if you click through. https://clojurians.slack.com/archives/C6N245JGG/p1598636978327300
Hi all,
I am building a node application using express.js and shadow-cljs. While running $ shadow-cljs watch app
I get .-params
from req but once I run $ shadow-cljs release app
and run the node application, (.-params req)
is null. Does anyone know how I can resolve this?
@lilokoego annotate req
with ^js req
. see https://shadow-cljs.github.io/docs/UsersGuide.html#externs
Hi @U05224H0W I can't seem to annotate results of the function cljs.core.async.interop/<p!
For example, I have
(let [browser (<p! (.launch ^js puppeteer)]
(.newPage ^js browser))
and I get the warning Cannot infer target type in expression (. inst_8232 (newPage))
.
Am I missing something?if you are building for node and don't care about filesize you can also just set :compiler-options {:optimizations :simple}
. that doesn't require externs.
Is there any reason to use (nth "foobar" index)
over (.charAt "foobar" index)
when fetching a char from a string?
:thumbsup:
Also performance, when important
The performance bit is what I was curious about actually. I had a look at the implementation in the Clojurescript repo. There was too much going on for me to grok all of it quickly, but seems like the nth
function had to pass through several layers of cljs functions, (whereas .charAt
basically goes straight from JS to native code) but I wondered how much of a penalty that would be, if any.
Recently we've added a few intrinsic optimizations here and there that leverage type inference. So for example, such an optimization for nth
could conceivably see that it is being applied to a string and then just emit the direct call to .charAt
(probably as well as with the argument checks)
An example candidate intrinsic along those lines is https://clojure.atlassian.net/browse/CLJS-3195
My general feeling on this subject is would be to just use nth
unless the code is in a spot where directly calling .charAt
is needed for perf reasons.
Over time, the compiler can improve and take care of these sorts of things for you. So in general, I'd just stick to using the standard library.
Good advice @U04VDQDDY, and that's interesting about the optimizations. The more I use CLJS the more I want to spend some time digging into the compiler/std code. Seems like a lot of interesting stuff in there.