This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-31
Channels
- # adventofcode (4)
- # ai (1)
- # announcements (13)
- # babashka (1)
- # beginners (42)
- # calva (15)
- # chlorine-clover (28)
- # cider (7)
- # cljsrn (1)
- # clojure (3)
- # clojure-china (1)
- # clojure-dev (4)
- # clojure-europe (7)
- # clojure-losangeles (1)
- # clojure-nl (3)
- # clojure-nlp (2)
- # clojure-sweden (12)
- # clojure-uk (2)
- # clojurescript (30)
- # code-reviews (36)
- # core-async (5)
- # cursive (10)
- # data-science (1)
- # datalevin (1)
- # fulcro (11)
- # introduce-yourself (1)
- # lsp (10)
- # malli (7)
- # minecraft (24)
- # missionary (10)
- # monads (6)
- # nrepl (4)
- # off-topic (11)
- # portal (4)
- # rdf (1)
- # reagent (3)
- # releases (4)
- # shadow-cljs (4)
- # spacemacs (4)
Hi, I created a simple blog with Luminus (SPA) but initial loading for app.js
is slow.
I created the project with the following command
lein new luminus blog +reitit +postgres +reagent +auth
dependencies are in the snippet.
Slow like a couple of seconds I got the cljs library loaded and did the first DOM rendered. In local I get ~210ms. but on 5$ droplet on digital ocean this became a couple of seconds. 1GB CPU in not enough for cljs+sci? Or I missed some code optimization with shadowcljs?@eliascotto94 if you did everything correctly then CLJS shouldn't even run on the server at all. you just have the .js file thats served as a simple static file. if you are actually compiling on the server then that will be rather slow yes.
Yes the /cljsbuild
directory is there with app.js
and /cljs-runtime
so is compiled. Itβs served by ring-undertow
I think. So where I should look?
(defn home-page [request]
(layout/render request "home.html"))
(defn home-routes []
[""
{:middleware [middleware/wrap-csrf
middleware/wrap-formats]}
["/" {:get home-page}]])
and home.html
contains
{% script "/js/app.js" %}
first of all you should be doing a release build for the JS. normally shadow-cljs release app
. that would produce only a single file and no cljs-runtime
dir
but it might not be related to CLJS at all and rather the droplet thing just starting the java server on demand
I have a protocol I want to extend onto all vectors. In clj, I'm extending onto clojure.lang.IPersistentVector
. What's the proper type to extend onto in cljs? I see both cljs.core/IVector
and cljs.core/PersistentVector
but I'm not sure how to evaluate which is correct.
It's the latter
In cljs you can't extend protocols to other protocols - the latter is the concrete type though so that will do it!
https://github.com/sicmutils/sicmutils/blob/main/src/sicmutils/collection.cljc#L116
In this namespace I do a similar thing as what you're asking for maps, sequences and vectors, and these were all the parallels I could find.
This is relevant too if you want your function to work for type that has implemented the vector protocol, not just the clojure provided type: https://clojurians.slack.com/archives/C07UQ678E/p1640803248285400
thank you for the thorough information
I am trying to use npm xstyled package in a shadow cljs project. I required the package and xstyled has this import style
import { x } from '@xstyled/styled-components'
I did this in cljs
["@xstyled/styled-components" :refer [x]]
xstyled says you access the components in dot notation like x.div
This did not work in cljs
[:> x.div ]
However I am using the PreFlight
import for base styles from xstyled working fine.
Any ideas would be greatly appreciated. ThanksIf you don't see anything useful if the log output, replace :refer [x]
with :as x
and check again.
kk will try that thanks
I get a bunch of this not quite sure what to make of it
#js {:a #js {$$typeof #object[Symbol(react.forward_ref)], :render #object[forwardRef], :attrs #js [],
Got it it's :refer [x.div]
@U02SFPVCRRS thats suprising i would have expected it to be import { export } from "module-name"; to (:require ["module-name" :refer (export)]) As per https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages
this just isn't valid interop. :refer [x]
gives you a local reference named x
. x.div
is not valid. (.-div x)
or (. x -div)
would be the proper way to get it. :refer [x.div]
is totally invalid and maybe just happens to work by accident (could be considered a bug)
interesting very new to clojure and clojurescript so would i report this as a bug to shadow cljs? or at least get clarification there?
I'm not entirely sure what you are suggesting. Do I write something like this in hiccup
[:> . x -div]
or does that go in the require? I want to do it the right way so it doesn't break later on. I have tried just [x]
in the require with the previous pattern in hiccup is that where you are suggesting the change in the require I Just got confused by the ()
parens then seeming that pattern should go in the function but doesn't seem to work for me?
What x.div
is in JavaScript becomes (.-div x)
in ClojureScript. So you'd use [:> (.-div x)]
.
In some cases, the a.b
form works but I guess it works only when there's js/
in front, like in js/console.log
- you can just write (js/console.log "something")
instead of (.log js/console "something")
(no dash because it's function call and not a property access).
And you can write [div]
instead of [:> (.-div x)]
if you do (def div (reagent/adapt-react-class (.-div x)))
.
ok thanks, should work now. Still getting used to this syntax, thanks for the help