Is there a cleaner way to do this? I don’t need th...
# announcements
a
Is there a cleaner way to do this? I don’t need the reference to the
stateDelegate
aside from the constructing the backing field and the public read-only state
Copy code
// util
inline operator fun <T> StateFlow<T>.getValue(thisObj: Any?, property: KProperty<*>): T = value
inline operator fun <T> MutableStateFlow<T>.setValue(thisObj: Any?, property: KProperty<*>, value: T) {
    this.value = value
}

// usage
private val stateDelegate: MutableStateFlow = MutableStateFlow(...)
private var _state: State = stateDelegate
val state: StateFlow<State> = stateDelegate

fun foo() {
    _state = State(...)
}
I guess if I could somehow get the delegate instance of the delegated property…