Fork me on GitHub
#reagent
<
2018-08-01
>
rnagpal14:08:18

This part is quite confusing

justinlee16:08:08

@rnagpal what do you mean by >When I add logs statements I see temp-reaction being set as the ratom which the component uses

justinlee16:08:48

I believe the temp-reaction thing is a performance optimization to avoid creating reaction objects when there are no watchers. Specifically this optimization: https://github.com/reagent-project/reagent/blob/5693716a7559a4f31bf2baf85378b3394a54e84e/src/reagent/ratom.cljs#L505

rnagpal16:08:18

The first line you pointed @lee.justin.m just sets the counter. But when I print temp-reaction in run-in-reaction function, I see different value of temp-reaction everytime

rnagpal16:08:18

Which seems to be a reaction obj (sorry I previously mentioned ratom)

justinlee16:08:23

so keep in mind that Reaction has mutable fields

eoliphant16:08:42

Hi, I’ve a quick question about adapt-react-class, etc. So,I’m using a react lib, did the clojure thing and wrote a couple functions to scan the source spit out a namespace with the require’s and a bunch def’s that just call adapt-react-class. This lib uses JSS so I have to set classes in my components. Does an adapted react class map :class from hiccup to :className? It doesn’t appear to, which is fine in general but in cases where it’s dynamic, I’m not getting to use the reagent :class [...] handling

justinlee16:08:47

the code is creating an empty reaction, and then it goes and mutates all those fields if needed

rnagpal16:08:37

I didnt see where that mutation is happening. I did see the counter thing, but didnt see where other parts of this reaction are set

eoliphant16:08:22

ok nvm lol. I was doing this late last night.. and was using :classes for some ungodly reason..

justinlee17:08:12

See the (set! (.-f r) f) and related lines? Those lines mutate the temp-reaction

justinlee17:08:39

The reason for these shenanigans is a performance optimization. After deref-capture runs f, run-in-reaction checks to see if anything bothered to watch whether f actually derefed any atoms. If not, then it just returns the value of (f). if something did watch f did actually deref anything, only then does it actually cache the reaction on the key of obj

justinlee17:08:08

actually I think I have the “watcher” and the “watching” backwards. run-in-reaction ultimately stores a list of what is being watched on the cljsRatom property of each component (fixed)

rnagpal17:08:43

Thanks @lee.justin.m will go though the code in some time and will try to make sense based on what you mentioned

rnagpal17:08:53

Thanks for helping me

justinlee17:08:08

well those were good questions. i finally understand wtf is going on with reactions

rnagpal17:08:13

I am adding some notes in the code, once it makes sense and I get the full picture, we can pick and add it to master

justinlee17:08:50

and actually, i think i realized the fundamental thing that has bugged me about reagent: because it performs watches at the ratom level, you effectively have to declare cursors everywhere. this is because there is no way to intercept get-in to get better watch lists. in in some way it defeats the purpose in the case where you store everything in a single atom

p-himik03:08:55

I did not follow the whole discussion, but the last part caught my attention. Does it mean that something can be done to improve re-frame performance? Because it stores all its data in a single ratom.

justinlee03:08:52

@U2FRKM4TW I’m pretty sure re-frame creates its own reactions or cursors based on the specific subscription you provide it. That’s kind of my point: requiring the user to provide a subscription isn’t a big deal (and arguably is better because it is more explicit). Reagent, however, goes through a lot of work to automatically track what you derefence in the body of the render function. I’m starting to think that’s pointless.

justinlee03:08:33

Re-frame could easily ditch all of the reaction/ratom machinery and just do what react-redux does: which is wrap each component and then force updates when the underlying subscription has changed. Cljs is perfect for that, because we already get superfast shallow equality comparisons due to the immutable datastructures.

p-himik03:08:07

Got it, thanks! @U051MTYAB Would it make sense to attempt something like that in re-frame?

mikethompson03:08:08

@U2FRKM4TW I haven't followed this thread, but recently it looks like strong assertions based on shallow knowledge. So, no, I won't be attempting anything like that :-)

justinlee03:08:40

well excuse me then