allan.conda
12/10/2020, 8:24 AMstateDelegate
aside from the constructing the backing field and the public read-only state
// 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(...)
}
allan.conda
12/10/2020, 8:28 AM