Remove duplicating property update notification in VisionBase

This commit is contained in:
Alexander Nozik 2021-01-13 12:38:42 +03:00
parent 4820082248
commit 19513656bd
4 changed files with 26 additions and 30 deletions

View File

@ -30,7 +30,7 @@ public val StringValueChooser: FunctionalComponent<ValueChooserProps> =
val keyDown: (Event) -> Unit = { event ->
if (event.type == "keydown" && event.asDynamic().key == "Enter") {
value = (event.target as HTMLInputElement).value
if(value!= props.item.string) {
if (value != props.item.string) {
props.valueChanged?.invoke(value.asValue())
}
}
@ -50,16 +50,14 @@ public val StringValueChooser: FunctionalComponent<ValueChooserProps> =
@JsExport
public val BooleanValueChooser: FunctionalComponent<ValueChooserProps> =
functionalComponent("BooleanValueChooser") { props ->
var checkedValue by useState(props.item.boolean ?: false)
val handleChange: (Event) -> Unit = {
val newValue = (it.target as HTMLInputElement).checked
checkedValue = newValue
props.valueChanged?.invoke(newValue.asValue())
}
styledInput(type = InputType.checkBox) {
attrs {
this.attributes["indeterminate"] = (checkedValue == null).toString()
checked = checkedValue
//this.attributes["indeterminate"] = (props.item == null).toString()
defaultChecked = props.item.boolean ?: false
onChangeFunction = handleChange
}
}
@ -68,24 +66,24 @@ public val BooleanValueChooser: FunctionalComponent<ValueChooserProps> =
@JsExport
public val NumberValueChooser: FunctionalComponent<ValueChooserProps> =
functionalComponent("NumberValueChooser") { props ->
var value by useState(props.item.string ?: "")
var innerValue by useState(props.item.string ?: "")
val keyDown: (Event) -> Unit = { event ->
if (event.type == "keydown" && event.asDynamic().key == "Enter") {
value = (event.target as HTMLInputElement).value
val number = value.toDoubleOrNull()
innerValue = (event.target as HTMLInputElement).value
val number = innerValue.toDoubleOrNull()
if (number == null) {
console.error("The input value $value is not a number")
console.error("The input value $innerValue is not a number")
} else {
props.valueChanged?.invoke(number.asValue())
}
}
}
val handleChange: (Event) -> Unit = {
value = (it.target as HTMLInputElement).value
innerValue = (it.target as HTMLInputElement).value
}
styledInput(type = InputType.number) {
attrs {
this.value = value
value = innerValue
onKeyDownFunction = keyDown
onChangeFunction = handleChange
props.descriptor?.attributes?.get("step").string?.let {

View File

@ -34,16 +34,16 @@ internal data class PropertyListener(
@SerialName("vision")
public open class VisionBase(internal var properties: Config? = null) : Vision {
init {
//used during deserialization only
properties?.onChange(this) { name, oldItem, newItem ->
if (oldItem != newItem) {
scope.launch {
notifyPropertyChanged(name)
}
}
}
}
// init {
// //used during deserialization only
// properties?.onChange(this) { name, oldItem, newItem ->
// if (oldItem != newItem) {
// scope.launch {
// notifyPropertyChanged(name)
// }
// }
// }
// }
@Transient
override var parent: VisionGroup? = null
@ -54,13 +54,13 @@ public open class VisionBase(internal var properties: Config? = null) : Vision {
protected fun getOrCreateConfig(): Config {
if (properties == null) {
val newProperties = Config()
newProperties.onChange(this) { name, oldItem, newItem ->
if (oldItem != newItem) {
scope.launch {
notifyPropertyChanged(name)
}
}
}
// newProperties.onChange(this) { name, oldItem, newItem ->
// if (oldItem != newItem) {
// scope.launch {
// notifyPropertyChanged(name)
// }
// }
// }
properties = newProperties
}
return properties!!

View File

@ -42,7 +42,6 @@ public abstract class MeshThreeFactory<in T : Solid>(
//add listener to object properties
obj.onPropertyChange(three.updateScope) { name ->
println("Property $name of mesh ${mesh.name} updated")
when {
name.startsWith(Solid.GEOMETRY_KEY) -> {
val oldGeometry = mesh.geometry as BufferGeometry

View File

@ -47,7 +47,6 @@ public object ThreeReferenceFactory : ThreeFactory<SolidReferenceGroup> {
//TODO apply child properties
obj.onPropertyChange(three.updateScope) { name->
println("Property $name of reference ${object3D.name} updated")
if (name.firstOrNull()?.body == REFERENCE_CHILD_PROPERTY_PREFIX) {
val childName = name.firstOrNull()?.index?.toName() ?: error("Wrong syntax for reference child property: '$name'")
val propertyName = name.cutFirst()