re-frame

2023-08-29T17:38:39.219539Z

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.

isak 2023-08-29T17:44:01.695179Z

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.

2023-08-29T17:49:53.392139Z

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 @isak 👍.

👍 1
p-himik 2023-08-29T18:55:35.518719Z

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.

2023-08-29T22:18:59.594259Z

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

👍 1
M 2023-08-31T19:05:42.173459Z

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

M 2023-08-31T19:07:28.010459Z

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.

🙌 1