Change Configurable config name

This commit is contained in:
Alexander Nozik 2021-07-31 17:06:17 +03:00
parent 8763d63e28
commit 3ba5a9076b
7 changed files with 14 additions and 12 deletions

View File

@ -12,6 +12,7 @@
- Relaxed type restriction on `MetaConverter`. Now nullables are available. - Relaxed type restriction on `MetaConverter`. Now nullables are available.
- **Huge API-breaking refactoring of Meta**. Meta now can hava both value and children. - **Huge API-breaking refactoring of Meta**. Meta now can hava both value and children.
- **API breaking** `String.toName()` is replaced by `Name.parse()` - **API breaking** `String.toName()` is replaced by `Name.parse()`
- **API breaking** Configurable`config` changed to `meta`
### Deprecated ### Deprecated
- Direct use of `Config` - Direct use of `Config`

View File

@ -4,7 +4,7 @@ plugins {
allprojects { allprojects {
group = "space.kscience" group = "space.kscience"
version = "0.5.0-dev-4" version = "0.5.0-dev-5"
} }
subprojects { subprojects {

View File

@ -9,11 +9,11 @@ public interface Configurable {
/** /**
* Backing config * Backing config
*/ */
public val config: MutableMeta public val meta: MutableMeta
} }
public fun <T : Configurable> T.configure(meta: Meta): T = this.apply { config.update(meta) } public fun <T : Configurable> T.configure(meta: Meta): T = this.apply { this.meta.update(meta) }
@DFBuilder @DFBuilder
public inline fun <T : Configurable> T.configure(action: MutableMeta.() -> Unit): T = apply { config.apply(action) } public inline fun <T : Configurable> T.configure(action: MutableMeta.() -> Unit): T = apply { meta.apply(action) }

View File

@ -1,7 +1,6 @@
package space.kscience.dataforge.meta package space.kscience.dataforge.meta
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.dataforge.names.* import space.kscience.dataforge.names.*
import space.kscience.dataforge.values.EnumValue import space.kscience.dataforge.values.EnumValue
import space.kscience.dataforge.values.Value import space.kscience.dataforge.values.Value
@ -385,7 +384,6 @@ private class MutableMetaImpl(
/** /**
* Append the node with a same-name-sibling, automatically generating numerical index * Append the node with a same-name-sibling, automatically generating numerical index
*/ */
@DFExperimental
public fun MutableMeta.append(name: Name, meta: Meta) { public fun MutableMeta.append(name: Name, meta: Meta) {
require(!name.isEmpty()) { "Name could not be empty for append operation" } require(!name.isEmpty()) { "Name could not be empty for append operation" }
val newIndex = name.lastOrNull()!!.index val newIndex = name.lastOrNull()!!.index
@ -397,13 +395,10 @@ public fun MutableMeta.append(name: Name, meta: Meta) {
} }
} }
@DFExperimental
public fun MutableMeta.append(key: String, meta: Meta): Unit = append(Name.parse(key), meta) public fun MutableMeta.append(key: String, meta: Meta): Unit = append(Name.parse(key), meta)
@DFExperimental
public fun MutableMeta.append(name: Name, value: Value): Unit = append(name, Meta(value)) public fun MutableMeta.append(name: Name, value: Value): Unit = append(name, Meta(value))
@DFExperimental
public fun MutableMeta.append(key: String, value: Value): Unit = append(Name.parse(key), value) public fun MutableMeta.append(key: String, value: Value): Unit = append(Name.parse(key), value)
///** ///**

View File

@ -75,6 +75,12 @@ private class ObservableMetaWrapper(
override fun set(name: Name, meta: Meta) { override fun set(name: Name, meta: Meta) {
val oldMeta = get(name) val oldMeta = get(name)
origin[name] = meta origin[name] = meta
// if meta is observable propagate changes from it
if(meta is ObservableMeta){
meta.onChange(this) { changeName ->
setMeta(name + changeName, meta[changeName])
}
}
if (oldMeta != meta) { if (oldMeta != meta) {
changed(name) changed(name)
} }

View File

@ -7,9 +7,9 @@ import space.kscience.dataforge.names.Name
* A base for delegate-based or descriptor-based scheme. [Scheme] has an empty constructor to simplify usage from [Specification]. * A base for delegate-based or descriptor-based scheme. [Scheme] has an empty constructor to simplify usage from [Specification].
* Default item provider and [MetaDescriptor] are optional * Default item provider and [MetaDescriptor] are optional
*/ */
public open class Scheme : Described, MetaRepr, MutableMetaProvider { public open class Scheme : Described, MetaRepr, MutableMetaProvider, Configurable {
public var meta: ObservableMutableMeta = MutableMeta() final override var meta: ObservableMutableMeta = MutableMeta()
private set private set
final override var descriptor: MetaDescriptor? = null final override var descriptor: MetaDescriptor? = null

View File

@ -53,7 +53,7 @@ public fun <T : Any> MutableMeta.update(
public fun <T : Any> Configurable.update( public fun <T : Any> Configurable.update(
spec: Specification<T>, spec: Specification<T>,
action: T.() -> Unit, action: T.() -> Unit,
): T = spec.write(config).apply(action) ): T = spec.write(meta).apply(action)
// //
//public fun <M : MutableTypedMeta<M>> MutableMeta.withSpec(spec: Specification<M>): M? = //public fun <M : MutableTypedMeta<M>> MutableMeta.withSpec(spec: Specification<M>): M? =