This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-01
Channels
- # beginners (59)
- # cider (3)
- # clara (4)
- # cljsjs (4)
- # clojure (144)
- # clojure-finland (2)
- # clojure-italy (10)
- # clojure-russia (2)
- # clojure-spec (7)
- # clojure-uk (53)
- # clojurescript (81)
- # cursive (30)
- # datomic (36)
- # defnpodcast (2)
- # editors (3)
- # emacs (4)
- # events (1)
- # fulcro (12)
- # off-topic (11)
- # onyx (14)
- # parinfer (2)
- # pedestal (12)
- # re-frame (3)
- # reagent (26)
- # shadow-cljs (81)
- # spacemacs (10)
- # sql (59)
- # uncomplicate (4)
- # yada (4)
@rnagpal what do you mean by
>When I add logs statements I see temp-reaction
being set as the ratom which the component uses
I think what you are seeing is the Reaction type being set in https://github.com/reagent-project/reagent/blob/5693716a7559a4f31bf2baf85378b3394a54e84e/src/reagent/ratom.cljs#L42
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
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
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
the code is creating an empty reaction, and then it goes and mutates all those fields if needed
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
ok nvm lol. I was doing this late last night.. and was using :classes
for some ungodly reason..
@rnagpal it happens in the when-not
clause of run-in-reaction
https://github.com/reagent-project/reagent/blob/5693716a7559a4f31bf2baf85378b3394a54e84e/src/reagent/ratom.cljs#L502-L511
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
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)
Thanks @lee.justin.m will go though the code in some time and will try to make sense based on what you mentioned
well those were good questions. i finally understand wtf is going on with reactions
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
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
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.
@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.
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.
Got it, thanks! @U051MTYAB Would it make sense to attempt something like that in re-frame?
@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 :-)