androidMain.tech.skot.view.live.MediatorSKLiveData.kt Maven / Gradle / Ivy
package tech.skot.view.live
class MediatorSKLiveData(initialValue: D) : MutableSKLiveData(initialValue) {
private val sources: MutableMap, SKLiveDataCommon<*>.AlwaysObserver> = mutableMapOf()
fun addSource(liveData: SKLiveData, onChanged: (s: S) -> Unit) {
val observer = liveData.makeAlwaysObserver(onChanged)
sources[liveData] = observer
if (hasActiveObserver()) {
observer.plug()
}
}
fun removeSource(liveData: SKLiveData) {
sources.remove(liveData)?.unPug()
}
override fun onActive() {
sources.values.forEach { it.plug() }
}
override fun onInactive() {
sources.values.forEach { it.unPug() }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy