Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pd2
fun <T> BaseObservable.bindable(initialValue: T, propertyId: Int): BindableProperty<T> {
return BindableProperty<T>(initialValue, this)
}
class BindableProperty<T>(initialValue: T,
private val observable: BaseObservable) : ObservableProperty<T>(initialValue) {
private var propertyId: Int = 0
override fun beforeChange(property: KProperty<*>, oldValue: T, newValue: T): Boolean {
return oldValue != newValue
}
override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) {
observable.notifyPropertyChanged(propertyId)
}
operator fun provideDelegate(observable: BaseObservable, property: KProperty<*>): BindableProperty<T> {
propertyId = PropertyMapper.bindableResourceIdForKProperty(property)
return this
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment