Fork me on GitHub
Adam Kalisz11:03:33

With the release of Clojure 1.11 and random-uuid being now present in Clojure I have looked into how random-uuid is implemented in CLJS as well and I think, we can get 2x better performance rather easily with this patch:


Might want to echo this in #cljs-dev

Adam Kalisz11:03:38

What do you think?


Given this

(def *a (clj->js {:foo {:bar 1}}))
How can I access :foo in the defined js object ?

Ferdinand Beyer12:03:15

Should be (.-foo *a)

Ferdinand Beyer12:03:04

(.-prop obj) is the ClojureScript equivalent to obj.prop in JavaScript (property access)


Yeah. Right


What’s the difference between (a.b) and (.b a).


I saw on the doc it should be the same:


But I do have a case where (.getMessage a) works but (a.getMessage) fails with

; Execution error (TypeError) at (<cljs repl>:1).
null is not an object (evaluating 'this.msg_'

Ferdinand Beyer12:03:18

Not sure why this does not work in your case. Frankly, I prefer using the Clojure-style syntax. (.getMessage a) would also work in Clojure

👍 1

There is not a way to calculate test coverage for Cljs tests, right? (I feel like this is a retoric question after checking this channel history 😢 )


Can someone tell me if something looks obviously wrong??

(ns polka.webrtc
  (:require-macros [cljs.core.async.macros :refer [go]])
   [ :as edn]
   [reagent.core :as r]
   [polka.testasync :as test]
   [cljs.core.async :as a :refer [<! >!]]
   [cljs.core.async.interop :refer-macros [<p!]]
   [reagent.dom :as rdom]))

(defn simple-component []
  (let [textArea (atom "")]
     [:button {:on-click #(create-offer-start)} "Generate Offer"]
     [:button {:on-click #(create-answer-start)} "Generate Answer"]

      {:value (.stringify js/JSON @textArea)
       :on-change #(swap! textArea (.. % -target -value))}]
     [:button {:on-click #(set-remote-desc)} "Set Remote Desc"]
     [:button {:on-click #(set-local-desc)} "Set Local Desc"]]))
But I am getting this error in the console in browser when I type in the text area:
cljs.core.js:16157 Uncaught TypeError: is not a function
    at eval (cljs.core.js:16157:89)
    at Function.eval [as cljs$core$IFn$_invoke$arity$2] (cljs.core.js:16158:3)
    at eval (polka.webrtc.js:971:29)
    at Object.reagent$impl$input$input_handle_change [as input_handle_change] (reagent.impl.input.js:72:106)
    at eval (reagent.impl.input.js:127:27)
    at HTMLUnknownElement.callCallback (module$node_modules$react_dom$cjs$react_dom_development.js:653:470)
    at Object.invokeGuardedCallbackImpl (module$node_modules$react_dom$cjs$react_dom_development.js:655:442)
    at invokeGuardedCallback (module$node_modules$react_dom$cjs$react_dom_development.js:56:424)
    at invokeGuardedCallbackAndCatchFirstError (module$node_modules$react_dom$cjs$react_dom_development.js:57:49)
    at executeDispatch (module$node_modules$react_dom$cjs$react_dom_development.js:111:250)
 [[reagent "1.1.1"]]

Pepijn de Vos15:03:04

#(swap! textArea (.. % -target -value))} should be reset! I think

Pepijn de Vos15:03:42

You're trying to use the value of the textarea as the function here


ah nice @UPHKPR2A3 thanks,. I no longer get the error, but i'm still not seeing the text change in the textarea


because you are creating a new atom with contents "" on every render


Shouldn’t this be a form 2 component instead?


you need a form-2 component

👍 1
Pepijn de Vos15:03:46

Or let-with I believe?


It also can't be a regular ClojureScript atom - it must be a Reagent atom.


Or r/with-let, as an alternative to a form-2 component, yes. Still gotta be a ratom though.


ahh nice, ok thanks this will help me fix it!


Finally, there's #reagent that's more appropriate for such questions.


slightly dated, but still relevant


oh looks great @U8VE0UBBR thanks. Im going to go through today. My tabs are scary right now 🥲


My recommendation, not that it counts, is to never solve an issue without understanding it thoroughly, deadlines be damned.


as the Beatles put it, Tomorrow Never Knows.

🔥 1

This is for my own project so i'm doing a mixture. Jamming as far as I can get till I get stuck, then dive deep into the stuff I don't know with at least some context

Pepijn de Vos15:03:05

How am I supposed to deal with uncaught errors originating in async code? It just prints some messy object that says "promise error". The stacktrace is just a bunch of async internals.

👀 1
Pepijn de Vos15:03:43

I kinda know which function it's coming from...

Pepijn de Vos15:03:33

But IIRC you just straight up can't use exceptions in async code, and there was also weird stuff where you can't have an async operation across a try boundary or something?


I would love to use the new :as-alias (new in Clojure 1.11.0) in Clojurescript. But I don’t understand enough about the interplay between Clojure, Clojurescript, and (in my case) shadow-cljs to know how to make it work, or if it is even within my power to do so. All I know is I get compilation errors when I try to use it in my full stack project in .cljs files. Works great for the Clojure side of the project.


CLJS probably doesn't support it yet. I don't see it in the changelog.


it's already supported in shadow-cljs - I've been using for a few months


yeah been available for a couple months now


I think I’m using the latest version of shadow-cljs, so why isn’t it working for me? How do I troubleshoot this?


the version you are using is logged on startup


so first figure out which version you are actually using 😉


if you are using shadow-cljs.edn only then package.json has your verison


if you use :lein or :deps in shadow-cljs.edn then the version is in project.clj or deps.edn


and also what is the error you get when you try to use this? 😛


I figured it out. The local package had latest version, but I was using global install that was out of date.


Hah! I probably ran that global install over two years ago and then never realized or thought about it. This may explain some other oddities I’ve noticed but weren’t annoying enough to go track down and figure out. Thanks for your help @U05224H0W, and for the most awesome shadow-cljs.


oh yeah don't let it get that far out of sync. a couple minor versions is probably fine but not too long


or don't use the global at all in the first place 😉


That’s probably the better practice, to not use global. Lesson learned.


well technically there has only been one breaking change in the global install in the last 4 years or so


so you happened to have the old one in global so it didn't see the "new" local one


normally the global will always look for a local install first


so there usually is no issue in having the global install out of sync. but just to be save using npx shadow-cljs over just shadow-cljs prevents this issue


hello, I'm trying to use re-com and I'm still trying to wrap my head around the tooling. In their README it says "You'll then need to include these asset folders in your app:". Should I manually copy those files to my assets folder, or are they supposed to be extracted from the package by some build tool?


re-com jar is a part of your classpath during the build process - you can set up a build tool to incorporate those assets into your app. Either by embedding into other assets or by simply copying them.


Same deal with NPM packages - if they have CSS there, you can incorporate it during the build process.


I see, I'm using shadow-cljs, but I don't think it has that kind of functionality, does it?


Asset management is out of the scope of shadow-cljs. However, it has build hooks which can run external programs - you can either bundle your CSS with them or just copy the files around. I think @U05224H0W mentioned at some point that he doesn't think that it's a good use of hooks and that instead something else should be used. Thomas, could you please confirm if I remember correctly and what that other thing is?


asset "bundling" is not supported. but this sounds like it just wants to load some stuff


for a production server you have to do this yourself. for development you can use :dev-http {8000 "classpath:public"}


and then in the html load /assets/css/bootstrap.css or so


depending on what you want to do hooks can make sense. most of the time there are better options though


Do they make sense as part of the release step to build SCSS (and make the SCSS compiler grab all the CSS from relevant NPM modules) and to copy some other resources from node_modules to an in-app dir?


I'll look into hooks and see if that makes sense. Thank you so much for your help!

👍 1