edvin / tornadofx2

TornadoFX 2.0
Apache License 2.0
156 stars 41 forks source link

Incorrect behavior of bindChildren(ObservableMap) #8

Open yevhenii-nadtochii opened 4 years ago

yevhenii-nadtochii commented 4 years ago

Having this:

    private val backedMap = LinkedHashMap<String, Int>().asObservable()
    private val mapProperty: SimpleMapProperty<String, Int> = SimpleMapProperty(backedMap)
    private val map: MutableMap<String, Int> by mapProperty

        vbox(spacing = 10) {
            bindChildren(mapProperty) { key, value ->
                label("$key: $value")
            }
        }

I get two bugs\unexpected things:

  1. Ordering of converted items is not preserved. I end up with different ordering in my map and vbox's children. But I use LinkedHashMap for backed map and expect that binding would preserve ordering of backed collection.
  2. Instead of updating items in vbox's children it just adds a new one each time I put already presented key in map (== update value).

For the first one the possible reason is using val sourceToTarget = HashMap<SourceTypeKey, TargetType>() in MapConversionListener for observable lists which vbox's one may be. So it doesn't honor which type of map a user uses. For the second It seems that it is referenced with Improving MapConversionListener #1183 but changes were not picked up to tornadofx2.

I wanted to at least try to fix it, but I couldn’t even build and connect tornadofx to my project locally :) So, could you please consider #7 Thank you!