Fork me on GitHub
#clojurescript
<
2021-12-31
>
olaf06:12:15

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?

thheller07:12:47

@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.

olaf07:12:44

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?

olaf07:12:47

(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" %}

thheller07:12:15

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

thheller07:12:49

but it might not be related to CLJS at all and rather the droplet thing just starting the java server on demand

thheller07:12:07

if thats not running continously then the startup will take a while

Dane Filipczak16:12:21

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.

Sam Ritchie16:12:12

It's the latter

Sam Ritchie16:12:41

In cljs you can't extend protocols to other protocols - the latter is the concrete type though so that will do it!

Sam Ritchie16:12:31

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.

Sam Ritchie16:12:11

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

🌷 1
Dane Filipczak17:12:18

thank you for the thorough information

anders kitson23:12:37

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. Thanks

p-himik23:12:35

Log x and see what it contains. Probably the :require should be changed.

p-himik23:12:57

If you don't see anything useful if the log output, replace :refer [x] with :as x and check again.

anders kitson23:12:05

kk will try that thanks

anders kitson23:12:50

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 [],

anders kitson01:01:50

Got it it's :refer [x.div]

Drew Verlee02:01:48

@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

thheller04:01:24

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)

anders kitson04:01:44

interesting very new to clojure and clojurescript so would i report this as a bug to shadow cljs? or at least get clarification there?

thheller05:01:00

I'm the shadow-cljs author so you can talk to me here πŸ˜‰

anders kitson13:01:07

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?

p-himik13:01:10

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).

p-himik13:01:11

And you can write [div] instead of [:> (.-div x)] if you do (def div (reagent/adapt-react-class (.-div x))).

anders kitson13:01:39

ok thanks, should work now. Still getting used to this syntax, thanks for the help

anders kitson13:01:11

Worked just great thx πŸŽ‰

πŸ‘ 1