Fork me on GitHub
#rum
<
2021-08-28
>
Pepijn de Vos08:08:55

Say I want to pass a key to a component and create a cursor out of it, how do I prevent making a new cursor every time the component is rerendered?

sova-soars-the-sora13:08:38

Just kinda shooting in the dark here, but maybe store it in an atom that lives outside the component?

Pepijn de Vos13:08:04

Hm. So in Reagent there are form-2 components where there is an outer function and an inner function that's actually what gets rendered.

Pepijn de Vos13:08:19

I'm thinking the Rum equivalent might be to make a mixin? Like, you add the cursor to the state on will-mount and remove it on did-unmount. Something like that?

Jan K14:08:21

Why don't you pass the cursor instead of the key? Or both if you need the key as well.

Pepijn de Vos14:08:47

I'm not really sure that would be an improvement. Say I have code like this

(for [key something
      :let [cursor (mycursor state key)]
  [my-cool-component cursor key])
When would that make a new cursor? I guess I'll have to experiment.

Pepijn de Vos15:08:45

As I understand it, React does something smart with the key of loop items so it doesn't rerender the whole loop, but I'm not sure at what level that happens.

Jan K15:08:55

Seems better to me. If the for runs only once then cursors are only created once, even when the components are re-rendered.

Pepijn de Vos19:08:43

Hm I kinda assumed everything in Cljs works with core.async but that was a bit of a miscalculation for the quite insane hacks I'm trying to do.

sova-soars-the-sora23:08:31

Have you seen this ?