Fork me on GitHub
#reagent
<
2017-07-13
>
pesterhazy08:07:07

@mrchance is state a ratom rather than a clojure.core/atom?

mrchance09:07:11

@pesterhazy Yes, it is. See the example I posted above, the div updates

pesterhazy09:07:49

@mrchance you're not showing where the atom is defined ๐Ÿ™‚

pesterhazy09:07:21

ah but maybe that's just the way code mirror works?

pesterhazy09:07:10

sort of like "uncontrolled components", i.e. when you're using input with :default-value: https://facebook.github.io/react/docs/uncontrolled-components.html

mrchance09:07:43

Hm, maybe? The code looks like it should work though

mrchance09:07:28

It sets the value of the internal code mirror instance to the prop received, if I read that correctly

pesterhazy09:07:41

looks like you're right

mrchance09:07:34

Whoops ๐Ÿ˜„

mrchance09:07:50

Haha, I actually checked the issues, but apparently missed that

pesterhazy09:07:07

you could work around that by manually re-mounting the whole thing

mrchance09:07:06

hm, the ticket mentions that someone started react-codemirror2, maybe I'll try that first

mrchance09:07:48

But that's actually something I've been wondering, how much different is the performance on remounting everything instead of updating components through ratoms?

mrchance09:07:17

I guess it's just the additional overhead of running the render methods for all components?

pesterhazy09:07:22

in the case of codemirror, it's probably a significant overhead

pesterhazy09:07:33

because it needs to tear down/set up its state

pesterhazy09:07:39

build the dom etc

pesterhazy09:07:08

in normal cases it's also significantly slower

mrchance09:07:25

ok, going to try the 2.0 then ๐Ÿ˜‰

pesterhazy09:07:37

you want to avoid remounting in general

pesterhazy09:07:52

note that comprehensive updates are fine

pesterhazy09:07:00

usually that's fast enough IME

mrchance09:07:19

That's what I thought. I read the rum intro, where they also recommend that as an easy way to re-render

pesterhazy09:07:51

can you link to the document? that's interesting

mrchance09:07:03

I guess for small components that's fine

pesterhazy09:07:36

but running mount again doesn't necessarily un-mount and re-mount

pesterhazy09:07:55

if the component is the same, it only triggers an update

pesterhazy09:07:58

react is smart like that

pesterhazy09:07:26

entirely re-mounting requires some hackery, like tricking react into thinking it's a different component, or using a different key

mrchance09:07:40

yeah, would want to avoid that

mrchance09:07:07

But it's probably still slower than only updating children deeper in the tree directly, right?

pesterhazy09:07:34

that's the optimal case yeah

mrchance09:07:54

My understanding was that the most performant way is to dereference ratoms as late as possible

pesterhazy09:07:09

that's right

mrchance09:07:23

nice, thanks again for the thorough help and explanations!

lwhorton15:07:20

what am I doing wrong here with r/track?

(defonce track-foo
  (reagent/track (fn [] (let [x @(a-ratom)] (do-something x)))
when I manually call a swap! or reset! to a-ratom the tracking function doesnt run .. but interestingly if I reload the code via figwheel, then the track triggers?

metametadata17:07:15

maybe atom shouldn't be in parens? @lwhorton

noisesmith17:07:38

yeah- that seems weird, unless a-ratom is a function returning an atomโ€ฆ

metametadata17:07:54

also according to https://reagent-project.github.io/news/news060-alpha.html the result of calling (r/track ...) must be derefed, e.g. in the component