viewmodel-savedstate: Add delegate for SavedStateHandle
Closed this issue · 0 comments
osipxd commented
Draft:
/** Creates delegate to read value from [SavedStateHandle]. */
inline fun <reified T> SavedStateHandle.value(key: String? = null): ReadOnlyProperty<Any?, T> {
return ReadOnlyProperty { _, property ->
if (null is T) {
get<T>(key ?: property.name) as T
} else {
checkNotNull(get(key ?: property.name))
}
}
}