re-frame

Schmoho 2025-02-25T14:39:53.644049Z

Hey, I know the last question was already re-com related, but I am currently wondering how to wire together re-frame and re-com https://re-com.day8.com.au/#/checkbox expect to be fed a r/atom as internal model, however this doesn't seem to make sense in the context of re-frame where I would wire the checked-property of the checkbox to a subscription - I guess I could use the event-handler to change db and then feed the subscription into the r/atom but that just seems like pointlessly introducing extra steps, so I wonder if I am missing the "correct" way somehow

p-himik 2025-02-25T14:44:28.350359Z

They don't expect a ratom. They expect a value or a deref-able thing, that they will then deref for you. And re-frame subscriptions are deref-able, so no conflict there. You can either use :model (rf/subscribe ...) or :model @(rf/subscribe ...). Both are fine with slightly differing implications.

Schmoho 2025-02-25T14:45:26.278459Z

thanks!

Schmoho 2025-02-25T20:40:47.803189Z

Mh, another re-com related question ... https://github.com/day8/re-frame-10x/tree/master crashes when I try to put a https://re-com.day8.com.au/#/tour in the db - first I do not really understand why, but since it seems to me that this only affects re-frame 10x and not really re-frame itself, I am wondering if there is a way for me to source a subscription from a ratom that is not in the db so I can write everything "the proper way" and swap it out in production

p-himik 2025-02-25T20:56:01.033209Z

I don't understand the question. What do you mean by "putting a re-com tour in the db"? What do you mean by "sourcing a subscription from a ratom"? How is it related to re-com tour? Finally, what does it all have to do with "rewriting everything the proper way"?

Schmoho 2025-02-25T21:02:01.232449Z

Ah sorry. So re-com tours have two methods if I understand it correctly, make-tour and start-tour. make-tour creates a map with two-r/atoms in it and some stuff and when I assoc that map into the db (in an event-handler) re-frame-10x crashes. Since this seems to be a problem with re-frame-10x specifically I figured I still want to put that tour map in the db, because that way I can write a subscription for it and put the conditional logic relevant for writing a tour in my components as usual. Since I also want to have re-frame-10x during development I thought maybe there is a way to use an r/atom (unrelated to the db) which I can source in the subscription during development, and when I'm done I can just take that r/atom out again and put the tour map in the db, source that in the subscription and I'm fine.

p-himik 2025-02-25T21:09:29.986289Z

I see. The tour implementation is not that great to be honest - it's definitely not suitable for a re-frame db. The impl is just 92 lines long, and that includes all the comments/docstrings/whitespace. So if I were you I would for sure rewrite it in my own code base with re-frame in mind.

👍 1
p-himik 2025-02-25T21:11:23.683659Z

An alternative would be to consider the states of all the tours to not be a part of the app's state. That way, there would be no need to store them in app-db. But that, of course, has plenty of its own downsides.

Schmoho 2025-02-25T22:02:49.154079Z

I'll have a look if I can manage that!

p-himik 2025-02-25T22:10:42.989769Z

Specific steps: 1. Make its state a plain data structure, without atoms 2. Make all its functions that change state manipulate that data 3. Store that state in re-frame's app-db 4. Create a subscription that gets you the full state of a tour by its ID 5. Create second-level subscriptions that, given a tour's ID, return a specific sub-state (current step, whether it's the first step, whether it's the last step, maybe something else if you need it) That's it.

❤️ 1
Schmoho 2025-02-25T22:22:37.736739Z

Oh wow! Thanks!

👍 1