rum

Pepijn de Vos 2021-08-28T08:36:55.001300Z

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-sora 2021-08-28T13:27:38.001700Z

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

Pepijn de Vos 2021-08-28T13:49:04.002400Z

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 Vos 2021-08-28T13:50:19.003400Z

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 K 2021-08-28T14:22:21.004Z

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

Pepijn de Vos 2021-08-28T14:59:47.006200Z

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 Vos 2021-08-28T15:00:45.007100Z

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 K 2021-08-28T15:25:55.008100Z

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

✅ 1
Pepijn de Vos 2021-08-28T19:57:43.009200Z

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-sora 2021-08-28T23:58:31.009400Z

Have you seen this ?