https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

josephivie

01/30/2019, 12:47 AM
I have a multiplatform UI library I’m going to be releasing soon. Currently, it uses a data binding system that uses this interface:
Copy code
interface ObservableProperty<T> {
    val value: T
    /**
     * Adds a listener to be notified when the value changes.
     */
    fun add(element: (T) -> Unit): Boolean
    /**
     * Removes a listener
     */
    fun remove(element: (T) -> Unit): Boolean
}
I can either leave this data binding system in place, or I could replace it with
ConflatedBroadcastChannel
from Kotlin Coroutines, which while experimental, does already exist. I’d like your opinions on which I should choose.
r

russhwolf

01/30/2019, 1:06 AM
Why not both? Give your users the choice of what API works better for them.
j

joseph_ivie

01/30/2019, 1:13 AM
Unfortunately, that is not a great option because the ViewFactory objects have functions that accept these observable properties - it would force the duplication of the entire library.
j

JL

01/30/2019, 1:32 AM
The broadcast channel seems overly bulky for such a function… on the other hand, what if you refactored it as an extension function to be able to add the class, that would make it easier to swap or choose
d

Dico

01/30/2019, 3:33 AM
ConflatedBroadcastChannel is thread safe, whereas most (all) UI code is single threaded. Consider a lighter approach that is most importantly quick to iterate and low on memory cost.
j

joseph_ivie

01/30/2019, 3:45 AM
Well, all right then. I'll be publishing
reacktive
, my observable property library, and
koolui
within the week, with support for JavaFX, Android, and JS, with iOS in the works. When I get there, any help would be appreciated!
🎉 2
👍 1