Refactor ItemProvider hierarchy
This commit is contained in:
parent
73b3bbe7fc
commit
d2ea1a975e
@ -1,6 +1,6 @@
|
|||||||
package space.kscience.dataforge.properties
|
package space.kscience.dataforge.properties
|
||||||
|
|
||||||
import space.kscience.dataforge.meta.Config
|
import space.kscience.dataforge.meta.ObservableMeta
|
||||||
import space.kscience.dataforge.meta.get
|
import space.kscience.dataforge.meta.get
|
||||||
import space.kscience.dataforge.meta.set
|
import space.kscience.dataforge.meta.set
|
||||||
import space.kscience.dataforge.meta.transformations.MetaConverter
|
import space.kscience.dataforge.meta.transformations.MetaConverter
|
||||||
@ -11,25 +11,25 @@ import space.kscience.dataforge.names.Name
|
|||||||
import space.kscience.dataforge.names.startsWith
|
import space.kscience.dataforge.names.startsWith
|
||||||
|
|
||||||
@DFExperimental
|
@DFExperimental
|
||||||
public class ConfigProperty<T : Any>(
|
public class MetaProperty<T : Any>(
|
||||||
public val config: Config,
|
public val meta: ObservableMeta,
|
||||||
public val name: Name,
|
public val name: Name,
|
||||||
public val converter: MetaConverter<T>,
|
public val converter: MetaConverter<T>,
|
||||||
) : Property<T?> {
|
) : Property<T?> {
|
||||||
|
|
||||||
override var value: T?
|
override var value: T?
|
||||||
get() = converter.nullableItemToObject(config[name])
|
get() = converter.nullableItemToObject(meta[name])
|
||||||
set(value) {
|
set(value) {
|
||||||
config[name] = converter.nullableObjectToMetaItem(value)
|
meta[name] = converter.nullableObjectToMetaItem(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onChange(owner: Any?, callback: (T?) -> Unit) {
|
override fun onChange(owner: Any?, callback: (T?) -> Unit) {
|
||||||
config.onChange(owner) { name, oldItem, newItem ->
|
meta.onChange(owner) { name, oldItem, newItem ->
|
||||||
if (name.startsWith(this.name) && oldItem != newItem) callback(converter.nullableItemToObject(newItem))
|
if (name.startsWith(this.name) && oldItem != newItem) callback(converter.nullableItemToObject(newItem))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun removeChangeListener(owner: Any?) {
|
override fun removeChangeListener(owner: Any?) {
|
||||||
config.removeListener(owner)
|
meta.removeListener(owner)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,13 +1,14 @@
|
|||||||
package space.kscience.dataforge.properties
|
package space.kscience.dataforge.properties
|
||||||
|
|
||||||
import space.kscience.dataforge.meta.ItemPropertyProvider
|
|
||||||
|
import space.kscience.dataforge.meta.ObservableItemProvider
|
||||||
import space.kscience.dataforge.misc.DFExperimental
|
import space.kscience.dataforge.misc.DFExperimental
|
||||||
import space.kscience.dataforge.names.startsWith
|
import space.kscience.dataforge.names.startsWith
|
||||||
import space.kscience.dataforge.names.toName
|
import space.kscience.dataforge.names.toName
|
||||||
import kotlin.reflect.KMutableProperty1
|
import kotlin.reflect.KMutableProperty1
|
||||||
|
|
||||||
@DFExperimental
|
@DFExperimental
|
||||||
public fun <P : ItemPropertyProvider, T : Any> P.property(property: KMutableProperty1<P, T?>): Property<T?> =
|
public fun <P : ObservableItemProvider, T : Any> P.property(property: KMutableProperty1<P, T?>): Property<T?> =
|
||||||
object : Property<T?> {
|
object : Property<T?> {
|
||||||
override var value: T?
|
override var value: T?
|
||||||
get() = property.get(this@property)
|
get() = property.get(this@property)
|
||||||
|
Loading…
Reference in New Issue
Block a user