-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialization support for FlowSettings #72
Comments
I haven't given this much thought yet. I want to get a sense of what is and isn't working about each part separately first. Serialization, like the original Settings API, is by nature synchronous which complicates things. For now, you can probably do something like |
My idea is to have serialization support when observing certain value using |
Oh I see. That's worth some thought but I still want to let everything settle a bit in it's current form first. In the meantime it should be fairly easy to get something working by hand if you look at what the |
Do you have an example of a working function that combines a serialized value with a flow? Thanks! |
Oh, the original workaround I had in mind here breaks in 1.0 with the untyped |
Wouldn't it be better to use kotlinx serialization to serialize and deserialize stuff, so implementing it on flows would be as simple as @OptIn(ExperimentalSettingsApi::class)
inline fun <reified T> FlowSettings.getDecodeValueFlow(
key: String,
defaultValue: T
): Flow<T> = getStringOrNullFlow(key).map {
it?.let {
Json.decodeFromString<T>(it)
} ?: defaultValue
}
@OptIn(ExperimentalSettingsApi::class)
inline fun <reified T> Settings.encodeValue(
key: String,
value: T,
) = set(key, Json.encodeToString(value)) kotlinx serialization supports kotlin multiplatform so there should be no compatibility issues |
@Giuliopime Something like that is easy to implement yourself if you want it. The purpose here is to use the settings store itself as the serialization format, rather than JSON. |
Are there any ideas or plans how to introduce
kotlinx.serialization
support also forFlowSettings
?As both
multiplatform-settings-serialization
andmultiplatform-settings-coroutines
are independent it might end up in a completely new module, actually maybe more than one as we have alsonative-mt
anddatastore
variants.Or is there any other option that would not lead to module number explosion?
The text was updated successfully, but these errors were encountered: