Roar Gronmo
12/08/2019, 12:48 PMAdam Powell
12/08/2019, 2:50 PMFlow
is a bit of a challenge at the moment due to some incompatibilities between the version of the IR compiler the latest compose plugin is using and generating suspending code, but some clever module separation can work around it for now. We're pretty anxious to see these bugs get fixed soonLiveData
is a little bit easier, let me see if I can dig up the snippet to use as an observe()
effect for itfun <T> observe(data: LiveData<T>) = effectOf<T?> {
val result = +state<T?> { data.value }
val observer = +memo { Observer<T> { result.value = it } }
+onCommit(data) {
data.observeForever(observer)
onDispose { data.removeObserver(observer) }
}
result.value
}
val currentValue = +observe(myLiveData)
LiveData
value changes, and the LiveData
will have an active observer for the duration of that compositionRoar Gronmo
12/08/2019, 3:01 PMAsh
12/08/2019, 5:34 PMAndrew Kelly
12/09/2019, 7:25 AMAsh
12/10/2019, 5:21 AMAndrew Kelly
12/10/2019, 5:22 AM