2019-06-23 20:53:25 +00:00
|
|
|
package net.shadowfacts.cacao.util
|
|
|
|
|
|
|
|
import kotlin.reflect.KProperty
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
class ObservableLateInitProperty<T: Any>(val observer: (T) -> Unit) {
|
|
|
|
|
|
|
|
lateinit var storage: T
|
|
|
|
|
2019-06-25 22:06:17 +00:00
|
|
|
val isInitialized: Boolean
|
|
|
|
get() = this::storage.isInitialized
|
|
|
|
|
2019-06-23 20:53:25 +00:00
|
|
|
operator fun getValue(thisRef: Any, property: KProperty<*>): T {
|
|
|
|
return storage
|
|
|
|
}
|
|
|
|
|
|
|
|
operator fun setValue(thisRef: Any, property: KProperty<*>, value: T) {
|
|
|
|
storage = value
|
|
|
|
observer(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|