commonMain.io.github.kevincianfarini.monarch.mixins.ObservableJsonFeatureFlagManagerMixin.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-serialization-mixin-jvm Show documentation
Show all versions of kotlinx-serialization-mixin-jvm Show documentation
Multiplatform mixin that decode JSON feature flags
The newest version!
package io.github.kevincianfarini.monarch.mixins
import io.github.kevincianfarini.monarch.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.serialization.json.Json
/**
* An implementation of [ObservableFeatureFlagManagerMixin] that adds support for [JsonFeatureFlag] instances.
*/
public class ObservableJsonFeatureFlagManagerMixin(
/**
* The [Json] instance used to serialize and deserialze feature flag values. This value should adhere to the JSON
* requirements imposed by your [FeatureFlagDataStore] implementation's underlying data source.
*/
private val json: Json,
) : ObservableFeatureFlagManagerMixin, FeatureFlagManagerMixin by JsonFeatureFlagManagerMixin(json) {
public override fun valuesOfOrNull(
flag: FeatureFlag,
store: ObservableFeatureFlagDataStore
): Flow? = when (flag) {
is JsonFeatureFlag -> store.observeString(flag.key, flag.serializedDefault(json)).map { string ->
flag.deserialize(string, json)
}
else -> null
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy