Skip to content

Instantly share code, notes, and snippets.

@Aidanvii7
Last active June 15, 2017 16:05
Show Gist options
  • Save Aidanvii7/08cb7e0c6c399191d37f3fe412e242f2 to your computer and use it in GitHub Desktop.
Save Aidanvii7/08cb7e0c6c399191d37f3fe412e242f2 to your computer and use it in GitHub Desktop.
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