I have a multiplatform UI library I’m going to be ...
# multiplatform
j
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
Why not both? Give your users the choice of what API works better for them.
j
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
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
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
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