Android Jetpack DataStore item separation
I am trying to migrate to Jetpack DataStore from good ol' SharedPreferences and there is one thing I am struggling to come to terms with and that is the amount/size of the data pulling out of DataStore at once. SharedPreferences were asynchronous and it was usually used in a way that they had one accessor with over exhaustive list of getters and setters - not supersophisticated but worked fine. There wasn't an issue with fetching multiple settings that were not necessarily related to each other. DataStore is synchronous only, with suspend functions and Flows(which comes with its own set of headaches). DataStore offers options to pull out a single preference with the Flow or Flow of a user-defined set of preferences grouped in a data class. Here is my problem. I am not sure how to approach getting multiple preferences at once. This is something I can do with Flows combine and it works fine but this also has a limit on how many of you can get at once and it doesn't look great. combine( preferences.preferenceA, preferences.preferenceB, preferences.preferenceC, preferences.preferenceD, preferences.preferenceE ) I can still make it this amount of flows with previously mentioned data classes so the amount of data I can have at one asynchronous place is enough but in principle, this feels like I would be forced to couple data just for the sake of coupling. OR Just have one big preference object/data class with all of the preferences in it - basically how SharedPreferences were used before but this would make each "client" that would ever need something from it would hold all of it. Either of the solutions "sounds" like a wrong one.
I am trying to migrate to Jetpack DataStore
from good ol' SharedPreferences
and there is one thing I am struggling to come to terms with and that is the amount/size of the data pulling out of DataStore
at once.
SharedPreferences
were asynchronous and it was usually used in a way that they had one accessor with over exhaustive list of getters and setters - not supersophisticated but worked fine. There wasn't an issue with fetching multiple settings that were not necessarily related to each other.
DataStore
is synchronous only, with suspend fun
ctions and Flow
s(which comes with its own set of headaches). DataStore
offers options to pull out a single preference with the Flow
or Flow
of a user-defined set of preferences grouped in a data class
.
Here is my problem. I am not sure how to approach getting multiple preferences at once. This is something I can do with Flow
s combine
and it works fine but this also has a limit on how many of you can get at once and it doesn't look great.
combine(
preferences.preferenceA,
preferences.preferenceB,
preferences.preferenceC,
preferences.preferenceD,
preferences.preferenceE
)
I can still make it this amount of flows with previously mentioned data classes so the amount of data I can have at one asynchronous place is enough but in principle, this feels like I would be forced to couple data just for the sake of coupling.
OR
Just have one big preference object/data class with all of the preferences in it - basically how SharedPreferences
were used before but this would make each "client" that would ever need something from it would hold all of it.
Either of the solutions "sounds" like a wrong one.