ASMR/src/main/kotlin/net/shadowfacts/cacao/util/properties/ObservableLateInitProperty.kt

24 lines
465 B
Kotlin
Raw Normal View History

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
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)
}
}