Fork me on GitHub
#reagent
<
2021-11-20
>
Noah Bogart02:11:10

is it better to have a single state r/atom for a component that i make multiple cursors for, or multiple single-value r/atoms?

lispers-anonymous14:11:26

There is no right answer for this. I use re-frame, which has a single ratom that holds most state, and the app performs very well with just that one ratom. Like using a single state ratom, that state is global, and it needs to be managed with care. For small focused components that I want to re-use, sometimes multiple times on the same page, I will have that component use it's own local ratom to manage it's state.

👍 1
Noah Bogart14:11:13

I really gotta take some time to understand reframe cuz it’s been beyond my understanding in previous attempts. It seems really powerful

lispers-anonymous14:11:48

It is. Understanding reagent well help. If you find yourself doing a lot of work with a single global atom, and tracking and updating that atom starts to become unwieldy, maybe then it will be time to consider re-frame.

Noah Bogart14:11:16

I’m currently refactoring a somewhat messy reagent app that has a single global atom and then a bunch of namespace atoms which makes for a lot of complicated updates and hard to reason about code paths

Noah Bogart14:11:51

Seems like an appropriate time to try reframe!

Noah Bogart14:11:56

Thanks for the advice

lispers-anonymous14:11:14

Indeed. Good luck in your refactoring. Be sure to check out the #re-frame channel

Noah Bogart23:11:36

Thanks for the suggestion, the reframe tutorial on their site is much improved since I checked it out a couple years ago. I think it’ll work great for me!

Noah Bogart14:11:26

To follow up on that question, I read the docs and saw that cursors can take swap! and reset! calls, which act as swap! update-in calls on the base r/atom, which neatly handles my use case