Fork me on GitHub
#rum
<
2020-07-20
>
cmdrdats13:07:05

I've started using derived-atom as a way to aggregate stuff locally so that that has a reaction before deciding to re-render a component - see https://github.com/CmdrDats/rumperftest/blob/master/src/perftest.cljs#L36-L40 - I'm a bit worried about memory leak with this pattern - will the derived atom watchers get released when the component is no longer in scope? or is there a different way I should be doing this?

Roman Liutikov14:07:41

there's a related issue for derived atom and watchers https://github.com/tonsky/rum/issues/94

cmdrdats15:07:02

Thanks :) i did see this, but my question is a bit broader - would the pattern I'm using be considered as intended, or should I be doing something entirely different? I find this particularly when dealing with collections where I need to iterate through the collection to embed their components, but then if I just react on the collection itself, any change (obviously) rerenders the entire parent component

g7s08:07:15

@U050CLJ53 The pattern you describe is known (part of optimization of a component) and the issue you describe is also known as @U0FR82FU1 said above.

g7s08:07:31

Personally I use a hook that does the cleanup

cmdrdats08:07:00

@UKQS17P3L great, thanks for the feedback - use-derived-atom looks interesting - is this in a fork?

g7s08:07:45

Yes it is in a fork that I had made long ago.

cmdrdats08:07:16

ah, ok - I see the current rum code has:

(defn use-reducer [reducer-fn initial-value]
  [initial-value reducer-fn])

(defn use-effect!
  ([setup-fn])
  ([setup-fn deps]))

(defn use-callback
  ([callback] callback)
  ([callback deps] callback))

cmdrdats08:07:51

probably in prep for moving away from React?

cmdrdats08:07:11

I guess a similar effect might be achieved with a mixin if there's a registry of derived atoms against a component?

g7s08:07:47

Yeah exactly you can do that with a mixin as you describe