Fork me on GitHub
#clojurescript
<
2020-12-14
>
Michaël Salihi13:12:24

@jrychter Which React wrapper do you use? You should put a code block with an fuction example.

jrychter13:12:29

Rum. And narrowing it down to a simple code block isn't easy. But I think I have a working theory — the functions get cached somewhere and they do reference an atom, just a different one, because each render creates a new one and they keep referencing the previous one.

Michaël Salihi14:12:08

For your component with the local state/atom, did you use defc or defcs ? https://github.com/tonsky/rum#components-local-state

Michaël Salihi14:12:40

> rum.core/defcs is used instead of rum.core/defc. It allows you to get hold of the components’s state in the render function (it will be passed as a first argument).

jrychter14:12:42

Thanks Michael — I do know these things, this application has ~85k LOC and has been developed over the last 5 years or so. And yet — things still manage to surprise me sometimes.

jrychter14:12:17

I now know that some components deep down do not get updated (keeping old closures) and using an atom does not help, unless that atom is part of component state, otherwise every render gets a different atom. Very hairy. I'm brute-forcing it by using rum/with-key to force updates.

Michaël Salihi14:12:40

@jrychter ok, i didn't quite understand the request which is more complex than i initialy thought. Good luck.

jrychter14:12:32

Thanks! I should have explained it better.

jaide18:12:16

(cljs.analyzer.api/ns-resolve 'clojure.core 'map)

jaide18:12:05

Any reason why that’s giving me a can’t deref null? Seems like the state it’s trying to use doesn’t exist?

clyfe18:12:25

Where is is called from? env/compiler gets populated by the cljs compiler and makes such data visible at compile time, so that's info available in macros.

clyfe18:12:06

(cljs.analyzer.api/ns-resolve 'cljs.core 'map)
Does that ^ yield anything?

jaide21:12:37

Ah that might be it, I was trying to call that at runtime

currentoor19:12:26

What is the JS equivalent of go-loop? AFAIK async/await are like go/<! respectively. But I can't think of something with the looping nature of go-loop.

p-himik19:12:15

A self-recursive async function should be similar.

currentoor19:12:08

@U2FRKM4TW that won't blow the stack?

currentoor19:12:52

i didn't know JS had tail recursion

p-himik19:12:27

My knowledge of JS is limited - better check it rather than trust me. I think it shouldn't blow up the stack if you don't await the self-call. Otherwise, the setTimeout solution should work.

currentoor19:12:35

got it, thanks!

phronmophobic19:12:00

setTimeout with 0 as a delay will run some code at some point in the future . you can have a for/while loop in js with await statements, i believe

👍 3
Carlo21:12:36

there's something I don't like in the reagent code I'm writing, and I'd like to ask how this is commonly done: sometimes I pass to a child both an atom (maybe because I'm using a ref), and some concrete values that come from an atom in the parent. I don't like that they're not syntactically distinct. Do you usually prepend a ! to a variable denoting an atom?

p-himik21:12:47

re-com has a nice approach. Many arguments can be either atoms or concrete values. It check conditionally derefs them all.

🙌 3
Felix M21:12:42

Hi,, what are my options for sprinkling a few reactive components in a server side rendered Clojure app without going full SPA.  I'm looking to have form inputs filter the the db and return the results client side without incurring a full page refresh. #beginners #programming-beginners x-post from #clojure where they recommended I post here