Fork me on GitHub
#re-frame
<
2023-08-29
>
mguinada17:08:39

Hi folks. re-frame newbie here. I’m coding my first re-frame app and I’ve been wondering about ways to perform view data cleanup. Specifically, I’m curious if there are common patterns to purge the app db from a view’s specific data when the user navigates away from that view. Any feedback on this subject would be much appreciated. Cheers.

isak17:08:01

Since you use the term 'navigate', I guess you are using a router? I think that is the best place for such logic. You can add 'init' and 'cleanup' functions/events as metadata to your routes, then dispatch those automatically.

mguinada17:08:53

Indeed I am using a router. More specifically reitit, with supports attaching controllers to routes, and my first idea was to use these. Thanks for your input @U08JKUHA9 👍.

👍 2
p-himik18:08:35

As an alternative, if the amount of that data is not that large and you don't have a thousand routes, I'd simply leave it there. It might also bring the benefit of the data being already there when a user navigates to a previously visited route.

mguinada22:08:59

Interesting POV, sometimes we all tend to be over-obsessed with resource release. Well, at least I do. 😬 Thanks for the input @U2FRKM4TW 🙌!

👍 2
M19:08:42

Agreed with @U2FRKM4TW, but you can also use the stop controller if you need to clear anything specific.

M19:08:28

But if you do keep it all, make sure some level of id is in your paths. If you have {:widget {:data}} and you go between widgets as you navigate, you will see the old data for a time before the new data is loaded.