Hey! I was wondering if `StateKeeper` `consume`/`...
# decompose
p
Hey! I was wondering if
StateKeeper
`consume`/`register` methods could use the same technique (or have an overload) that
Json.encodeToString
does, so we don't have to pass the serializer manually, with something like
essentyJson.serializersModule.serializer()
? I think I can use
Json
instead of
essentyJson
and do an extension on my end, as the lib doesn't and is not expected to modify the
serializersModule
in the future, but it would be nicer to be shipped with the lib.
a
This was an explicit design decision to avoid having global configuration objects. There is a thread with some discussions and info: https://github.com/arkivanov/Decompose/issues/470#issuecomment-1748798479
❤️ 1
Btw, you can create the following functions in your project. Just keep in mind that it will crash at runtime if you forget to annotate your types with
@Serializable
.
Copy code
import com.arkivanov.essenty.statekeeper.StateKeeper
import kotlinx.serialization.serializer

inline fun <reified T : Any> StateKeeper.consume(key: String): T? =
    consume(key = key, strategy = serializer<T>())

inline fun <reified T : Any> StateKeeper.register(key: String, noinline supplier: () -> T?) {
    register(key = key, strategy = serializer<T>(), supplier = supplier)
}
🔥 1