commonMain.jetbrains.datalore.base.observable.property.DerivedProperty.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* Copyright (c) 2019. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.base.observable.property
import jetbrains.datalore.base.observable.collections.Collections
import jetbrains.datalore.base.observable.event.EventHandler
import jetbrains.datalore.base.observable.event.EventSource
import jetbrains.datalore.base.registration.Registration
/**
* Simplified version of [BaseDerivedProperty] which can depend on generic observable objects.
*/
abstract class DerivedProperty(initialValue: ValueT, vararg deps: EventSource<*>) :
BaseDerivedProperty(initialValue) {
private val myDeps: Array> = Collections.arrayCopy(deps)
private var myRegistrations: Array? = null
override fun doAddListeners() {
myRegistrations = Array(myDeps.size) { i -> register(myDeps[i]) }
}
private fun register(dep: EventSource): Registration {
return dep.addHandler(object : EventHandler {
override fun onEvent(event: EventT) {
somethingChanged()
}
})
}
override fun doRemoveListeners() {
for (r in myRegistrations!!) {
r.remove()
}
myRegistrations = null
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy