24 lines
476 B
Kotlin
24 lines
476 B
Kotlin
|
package net.shadowfacts.cacao.util.properties
|
||
|
|
||
|
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
|
||
|
|
||
|
operator fun getValue(thisRef: Any, property: KProperty<*>): T {
|
||
|
return storage
|
||
|
}
|
||
|
|
||
|
operator fun setValue(thisRef: Any, property: KProperty<*>, value: T) {
|
||
|
storage = value
|
||
|
observer(value)
|
||
|
}
|
||
|
|
||
|
}
|