preferencesDataStore is a function, instead of having a val, create a function that receives the UUID and that function will call preferencesDataStore with the appropriate name
Eduardo Dantas
10/25/2023, 5:58 PM
Just be sure to save and return the same dataStore everytime you call the function for the same UUID
Eduardo Dantas
10/25/2023, 6:06 PM
I don't have an IDE right now but I imagined something like this
Eduardo Dantas
10/25/2023, 6:06 PM
Copy code
typealias MyType = Int
class DataStore {
private val stores = ConcurrentHashMap<String, DataStore<MyType>>()
suspend fun get(uuid: String): DataStore<MyType> =
stores.getOrPut(uuid) {
preferencesDataStore(
name = PREFS_NAME,
produceMigrations = { context -> listOf(SharedPreferencesMigration(context, PREFS_NAME)) }
)
}
}