Created
April 21, 2017 03:45
-
-
Save forceLain/e74c9b82caa72e878938776c404f4452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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