Fork me on GitHub
#clojurescript
<
2021-09-15
>
Luke Harris00:09:21

Hi all, I'm running into an issue with figwheel hot reload time that I don't understand. I have a single function that when present in the file blows up the reload time to 24 seconds, and with it commented out reload time is 4 seconds. This function is a validator that steps through a block of data and checks to make sure that all user set options within the data are valid, and when it finds an invalid option it writes to a global state atom. It contains a bunch of doseq's to step through all of the data, including some nested doseq calls. If I swap out those doseq's for (dorun (for ...)) reload time is 8 seconds, and if I swap them out for (dorun (map ...)) it's back down to 4 seconds. Does anyone know why this is happening when using doseq? What's the "right" way to do iteration in clojurescript?

p-himik10:09:47

Hot reload time consists of three stages: • Compiling the code • Sending the code • Evaluating the code If you can figure out which of them takes the most time, it would be a good starting point. Also, there's #figwheel

Leaf Garland02:09:29

Hopefully someone can point me in the right direction to fix this issue. When starting a piggieback cljs repl some of us get this error, some of us do not. The repl works in most other ways, we can eval, run js, etc. We all have the same classpath, etc. clj.user=> (do (require 'cider.piggieback 'cljs.repl.browser) (cider.piggieback/cljs-repl (cljs.repl.browser/repl-env))) cljs.user=> (require 'our.application) Unexpected error compiling at (REPL:1). Not supported: class cljs.repl.browser.BrowserEnv$fn__7854

thinking-face 2
Leaf Garland04:09:10

Actually, not just piggieback - we get the same results with lein trampoline cljsbuild repl-listen

Mikko Koski07:09:01

I just spend quite a lot of time to get CLJS browser repl setup working nicely with piggieback and encountered many errors, but this was not one of those. You see the browser opening, index page loading fine, REPL connection made and no errors in browser Console?

Leaf Garland01:09:33

Hey, thanks for replying. We have narrowed it down (we think) to a version of timbre log library but we’re still not sure why some of us can require that ns and others cannot.

Leaf Garland01:09:52

And yes all other functionality seems fine.

Stuart15:09:54

Hi Guys, I have the following clojurescript code https://gist.github.com/stuartstein777/24087befcaeb40f6f7b6768c51dfca20 IT works, but I was getting console error:

template.cljs:244 Warning: Reactive deref not supported in lazy seq, it should be wrapped in doall:
This was stopping it from working properly. The doall I had to add was this line in app fn
(doall
  (for [[key repo] (helpers/keyed-collection repos)]
     (repo-summary key repo)))
Adding that fixed my problems, but it feels like a hack and I don't understand why I had to add it. Is it because within the for, I'm calling a function and that function derefs a reframe subscription? What is a better way to do this?

p-himik15:09:32

> Is it because within the `for`, I'm calling a function and that function derefs a reframe subscription? Exactly. > What is a better way to do this? Avoiding laziness when it comes to derefing ratoms.

p-himik15:09:46

doall, into, mapv, etc.

p-himik15:09:09

Also, stop using () with functions that are views. Use [] instead.

Stuart15:09:40

Thank you! Yeah, changing to using [] rather than () for my components.

👍 2
Stuart15:09:42

Man, the reagent and re-frame docs are really, really, good

Stuart15:09:57

Surprising, considering most open source libs I have to use have virtually no documentation at all

p-himik17:09:38

> Man, the reagent and re-frame docs are really, really, good Absolutely. :) I only wish Reagent also had good docstrings in the code.

Takis_19:09:48

How to send a promise from a go block? Clojurescript app

(defn foo []
  (go 1))
Node app
var r=await foo();   //how to make it to wait and get 1

p-himik19:09:32

You can't. Just as in Node, where you can't use that await out of the blue - you have to use it within an async function.

Takis_19:09:43

The goal is to send to a node app, a value from a go, i found this way(someone from here helped before some days) (take! (go 1) (fn [r] (cb r))) but this works with callbals, i want to use await/promise, any help appreciated

p-himik19:09:14

What do you mean by "send" exactly?

Takis_19:09:55

go to produce a promise, that node can await

Takis_19:09:07

its fine if its inside an asych function

Takis_19:09:39

if it was like (defn foo [] 1) i would call var r= foo();

p-himik19:09:49

You have to return a regular JS promise to Node, and then Node can await that promise.

Takis_19:09:24

ok but how go to return a regular js promise? i dont know how to do it

p-himik19:09:26

And you resolve that promise in the go block. That all assumes that you already have a go block that you don't want to change. If you do not have such a block, just do everything using promises.

p-himik19:09:51

Read online about JS promise API, then use JS-CLJS interop to create a promise, that's it.

Takis_19:09:16

how to make (go 1) to return a promise?

Takis_19:09:25

go returns a channel

p-himik19:09:13

You do not "make the go block return a promise". You return a promise from a CLJS function. That very same function also has a go block that resolves that promise. Node then calls that function, awaits that promise, and gets the result when the resolve is done within the go block.

p-himik19:09:05

(defn call-me-from-node []
  (js/Promise. (fn [resolve _]
                 (go (resolve 1)))))
I think that's how it would look like. I rarely construct promises, so might misremember things.

Takis_19:09:14

ok thank you alot for your time, i will try it : )

Takis_19:09:27

i will read also interop of CLJS

👍 2
Takis_20:09:14

i moved the question here, if anyone knows how to help

p-himik20:09:28

Did my example not help?

p-himik20:09:35

You would just have to do const that_1_from_go_block = await that_cljs_fn();.

Takis_20:09:24

1 min i will try it now

Takis_20:09:37

from node, i tried from clojurescript and i had some problem

luizmineo20:09:05

You can create a promise in your clojure function, and resolve it within your go block. Something like this

(defn my-async-func []
  (new js/Promise
       (fn [resolve _]
         (go
           (let [result (<! (async-op))]
             (resolve result))))))

Takis_20:09:45

i think it worked perfectly :)) i am just new to all those, creating npm libraries, async code etc

Takis_20:09:54

> c.call_me_from_node().then((v) => { console.log(v)}); Promise { <pending> } > 1

Takis_20:09:30

thank you all : )

p-himik20:09:06

A quick unsolicited advice - if at all possible, don't tackle the concepts all at once. CLJS+NodeJS+promises+core.async is a hell of a combination to learn that way.

Takis_20:09:28

i know i will go one by one slow, read all (i was also new in shadow-cljs so i had this also)

👍 2
emccue23:09:45

i'll plug https://github.com/funcool/promesa if you just need to do normal async stuff

emccue23:09:53

i'm personally not convinced core.async is useful on the frontend when most of what you would use go blocks for is for putting a single result onto a single channel per block - thats just promises with worse stacktraces

p-himik23:09:31

+ more bugs, core.async on CLJS is not perfect.

emccue00:09:50

I think one of the big draws for it on the frontend was that you could be uniform with a backend also using core.async

emccue00:09:50

but if you used promesa with virtual thread executors nowadays you wouldn't have that much reason to use core.async on the backend either (pending release of that in 2+ years)

Takis_20:09:15

its solved(on the thread) , thank you alot : )