re-frame

zachcp 2025-05-16T18:32:35.534959Z

I posted this in the UIX channel but was redirected here. I wonder if anyone has had experience with using multiple DBs. https://clojurians.slack.com/archives/CNMR41NKB/p1747414821222349

p-himik 2025-05-16T19:35:38.963899Z

There's an old issue with quite a lengthy discussion: https://github.com/day8/re-frame/issues/137 But what's the purpose of having multiple DBs in your case?

zachcp 2025-05-16T20:11:00.929939Z

Thank you. In my case, I am interested in using UIX/reframe to coordinate a set of React components and then mount multiple instances. I expect the state of each of those to be independent but they were bleeding into one another. Per Claude, I ended up adding an id in the DB for each DB-instance. That works but I thought there might be a simpler way.

zachcp 2025-05-16T20:11:32.008889Z

FYI: this is the WIP https://zachcp.github.io/livemol/

zachcp 2025-05-16T20:12:09.994879Z

each editor/molecule viz gets its own state.

zachcp 2025-05-16T20:12:21.980209Z

( its coming along nicely but needs some CSS love )

p-himik 2025-05-16T20:17:39.321789Z

Cool project! The main value-add of re-frame, at least the way I see it, is its central storage. It makes a lot of things trivial - global observability, automatic total state preservation, comprehensive undo-redo (well, not trivial, but much simpler than it would be otherwise), etc. If you don't really need any of that and can't think of any other reason why a single global storage could be beneficial to your app, then maybe going with bare Reagent would make more sense? You have something that resembles subscriptions - reactions and cursors (re-frame's subscriptions are actually just reactions). You don't have declarative events, but if you don't need observability then it should be fine to use regular functions. And if Reagent would indeed be more suitable, then maybe UIx will also work just fine without any other library. But I'm much less familiar with UIx and any patterns for state management there.

zachcp 2025-05-16T20:20:02.803149Z

@p-himik I totally agree. Except in my case it wasn't super clear how to pass the data up and down the render chain. re-frame provides a nice conceptual model for me. But now that its written and works I think I could potentially move to refactor in the reagent direction.

p-himik 2025-05-16T20:24:47.358869Z

Suppose you have two main components, A and B, that are completely independent in every regard. A can create its own global-for-A state, or you can create a global (def a-state (r/atom {...})) for it and pass it to A as an un-deref'ed ratom when you create the corresponding Hiccup. Same for B. Both A and B would then create sub-states using reactions that are appropriate for every sub-component. The deeper into the render chain you go, the deeper the nesting of reactions gets - the same thing is common with with subscriptions, only you don't create them dynamically.

zachcp 2025-05-16T20:29:21.562619Z

In my case I need A (code editor) to mutate the data for B. I guess I could put both A and B at the top?

zachcp 2025-05-16T20:29:48.582899Z

That would be simpler.....

p-himik 2025-05-16T20:33:50.100289Z

Ah, I thought you needed multiple editors with an associated visual component for each, where every editor+visuals pair is completely independent from any other such pair. So in the case that I was describing A and B are each such a pair.

zachcp 2025-05-16T20:36:07.754869Z

yeah. the idea is you can live edit and the VIZ will update. But the state gets tangly. (its not so bad but it was easier to design when I can just push/pull from a global - e.g. re-frame db)

p-himik 2025-05-16T20:38:51.957359Z

Yeah, I'd definitely use a single app-db for that and not seek any way to separate it - it would only make things harder, not easier. If you don't need to have multiple editors, just store all editor-related data under e.g. an :editor key in app-db and all the visuals-related data under :visuals, and so on. If you have data that's common in nature and isn't specific to any component, it would make sense to store it under its own key.

👍 1
zachcp 2025-05-16T20:41:11.360219Z

Thanks for the heads up. I might explore the reagent option now that I've got a working project. I do like Reagent's simplicity. Note: UIX solved the "it just works" problem which made getting started on a project straightforward.

👍 1