Add option for preserving local data on disconnect
Wanted to add a way to preserve local data on disconnect.
There is no change to default behaviour but if preserve is set to true it does not run the _cleanups. It's functional, however I am unsure if there are negative side-effects from not running _cleanups.
refs #1170
Thanks for your first pull request! :+1: :tada:
I just had a look at the changes.
however I am unsure if there are negative side-effects from not running _cleanups
Yes, this is the main task left to do here. We cannot skip all cleanups only to not remove the cached user data. You can find the cleanup functions in all the various modules/classes in src/ and see what they're doing.
I think one possible solution would be to set a global preserveUserDataOnDisconnect config, which could also be done ad-hoc when calling remoteStorage.disconnect() with the preserve argument. The respective cleanup functions could then skip deleting user data and settings when so configured.
Another solution would be to create a deleteLocalData() function that does nothing but clear all potential caching back-ends, plus the settings in localStorage when that's available. This would have the added benefit that it could be called after having disconnected, when the user wishes to remove all local data at some point later then. And a mix of the two ideas could be to implement idea no. 1 but also add this function, which then just changes the preserve config and runs cleanups again.
There are probably other routes to achieve our goal as well. I'm also wondering how we manage user expectations when one app clears the data on disconnect, while the next one preserves it.