Fix vision listening

This commit is contained in:
2025-06-14 17:59:11 +03:00
parent 29ab796807
commit 7f05e5a556
13 changed files with 32 additions and 15 deletions

View File

@ -11,6 +11,7 @@
### Removed
### Fixed
- Fix the problem where property listeners do not react on property child node changa
### Security

View File

@ -11,7 +11,7 @@ val dataforgeVersion by extra("0.10.1")
allprojects {
group = "space.kscience"
version = "0.5.0"
version = "0.5.1-dev-1"
}
subprojects {

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -20,7 +20,7 @@ kotlin{
// A workaround for https://youtrack.jetbrains.com/issue/KT-44101
val copyPlotlyResources by tasks.creating(Copy::class){
val copyPlotlyResources by tasks.registering(Copy::class){
dependsOn(":plotly-kt:plotly-kt-server:jvmProcessResources")
mustRunAfter(":plotly-kt:plotly-kt-server:jvmTestProcessResources")
from(project(":plotly-kt:plotly-kt-server").layout.buildDirectory.file("processedResources/jvm/main"))

View File

@ -22,7 +22,7 @@ kotlin {
jsMain {
dependencies {
api("app.softwork:bootstrap-compose:0.3.0")
api("app.softwork:bootstrap-compose:0.3.1")
api("app.softwork:bootstrap-compose-icons:0.3.0")
// implementation(npm("bootstrap", "5.3.3"))
// implementation(npm(" bootstrap-icons", "1.11.3"))

View File

@ -28,9 +28,8 @@ public interface ComposeHtmlVisionRenderer : ElementVisionRenderer {
public companion object
}
/**
* A compose-html renderer for a vision of given type
* A compose-html renderer for a vision of a given type
*/
public inline fun <reified T : Vision> ComposeHtmlVisionRenderer(
acceptRating: Int = ElementVisionRenderer.DEFAULT_RATING,

View File

@ -0,0 +1,18 @@
package space.kscience.visionforge.html
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
import kotlinx.coroutines.flow.map
import space.kscience.visionforge.Vision
import space.kscience.visionforge.flowProperty
import kotlin.reflect.KProperty1
@Composable
public fun <V : Vision, T> V.collectPropertyAsState(
property: KProperty1<V, T>,
propertyName: String = property.name,
): State<T> = flowProperty(propertyName)
.map { property.get(this@collectPropertyAsState) }
.collectAsState(property.get(this))

View File

@ -118,7 +118,7 @@ public interface MutableVision : Vision {
override suspend fun receiveEvent(event: VisionEvent) {
if (event is VisionChange) {
if (event.children?.isNotEmpty() == true) {
error("Vision is not a group")
error("Received vision group change event, but $this Vision does not handle children changes")
}
event.properties?.let {
updateProperties(it, Name.EMPTY)
@ -130,7 +130,7 @@ public interface MutableVision : Vision {
name: Name,
inherited: Boolean = isInheritedProperty(name),
useStyles: Boolean = isStyledProperty(name),
): MutableMeta = properties.getOrCreate(name).withDefault { suffix->
): MutableMeta = properties.getOrCreate(name).withDefault { suffix ->
val propertyName = name + suffix
if (useStyles) getStyleProperty(propertyName)?.let { return@withDefault it }
if (inherited) parent?.readProperty(propertyName, inherited, useStyles)?.let { return@withDefault it }

View File

@ -9,6 +9,7 @@ import space.kscience.dataforge.meta.Value
import space.kscience.dataforge.meta.descriptors.get
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.parseAsName
import space.kscience.dataforge.names.startsWith
import kotlin.reflect.KProperty1
private fun Vision.withAncestors(): List<Vision> = buildList {
@ -42,7 +43,7 @@ public fun Vision.flowProperty(
}
combinedFlow.filterIsInstance<VisionPropertyChangedEvent>().collect { event ->
if (event.propertyName == propertyName || (useStyles && event.propertyName == Vision.STYLE_KEY)) {
if (event.propertyName.startsWith(propertyName) || (useStyles && event.propertyName == Vision.STYLE_KEY)) {
emit(readProperty(event.propertyName, inherited, useStyles))
}
}
@ -89,7 +90,7 @@ public fun Vision.useProperty(
} else {
eventFlow
}.filterIsInstance<VisionPropertyChangedEvent>().onEach { event ->
if (event.propertyName == propertyName || (useStyles && event.propertyName == Vision.STYLE_KEY)) {
if (event.propertyName.startsWith(propertyName) || (useStyles && event.propertyName == Vision.STYLE_KEY)) {
callback(readProperty(event.propertyName, inherited, useStyles))
}
}.collect()
@ -134,7 +135,7 @@ public fun <V : Vision, T> V.onPropertyChange(
scope: CoroutineScope = manager?.context ?: error("Orphan Vision can't observe properties. Use explicit scope."),
callback: suspend V.(T) -> Unit,
): Job = inheritedEventFlow().filterIsInstance<VisionPropertyChangedEvent>().onEach {
if (it.propertyName.toString() == property.name) {
if (it.propertyName.startsWith(property.name)) {
callback(property.get(this))
}
}.launchIn(scope)

View File

@ -73,5 +73,6 @@ internal class PropertyFlowTest {
collectorJob.cancel()
assertEquals(listOf(22, 11, 33), collectedValues)
println("finished")
}
}

View File

@ -2,7 +2,7 @@ plugins {
id("space.kscience.gradle.mpp")
}
val kmathVersion = "0.4.1"
val kmathVersion = "0.4.2"
kscience {
jvm()

View File

@ -1,6 +1,5 @@
package space.kscience.visionforge.three
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.visionforge.html.*
import space.kscience.visionforge.solid.Solids
import java.awt.Desktop
@ -9,7 +8,6 @@ import java.nio.file.Path
public val VisionPage.Companion.threeJsHeader: HtmlFragment get() = scriptHeader("js/visionforge-three.js")
@DFExperimental
public fun Solids.makeThreeJsFile(
path: Path? = null,
title: String = "VisionForge page",

View File

@ -9,7 +9,6 @@ import kotlin.test.Test
class TestServerExtensions {
@Suppress("UNUSED_VARIABLE")
@Test
fun testServerHeader(){
val string = createHTML().apply {