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.
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.
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 👍.
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.
Interesting POV, sometimes we all tend to be over-obsessed with resource release. Well, at least I do. 😬 Thanks for the input @p-himik 🙌!
Agreed with @p-himik, but you can also use the stop controller if you need to clear anything specific.
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.