Skip to content

Instantly share code, notes, and snippets.

@forceLain
Created April 21, 2017 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forceLain/e74c9b82caa72e878938776c404f4452 to your computer and use it in GitHub Desktop.
Save forceLain/e74c9b82caa72e878938776c404f4452 to your computer and use it in GitHub Desktop.
class SerializableObservable<T : Serializable>(private val onChange: (oldValue: T?, newValue: T?) -> Unit) : ReadWriteProperty<Any?, T?>, Serializable {
var value: T? = null
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
return value
}
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
val old = this.value
this.value = value
onChange.invoke(old, this.value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment