20 lines
389 B
Kotlin
20 lines
389 B
Kotlin
|
package net.shadowfacts.cacao.util.properties
|
||
|
|
||
|
import kotlin.reflect.KProperty
|
||
|
|
||
|
/**
|
||
|
* @author shadowfacts
|
||
|
*/
|
||
|
class ObservableLazyProperty<Value>(val create: () -> Value, val onCreate: () -> Unit) {
|
||
|
|
||
|
var storage: Value? = null
|
||
|
|
||
|
operator fun getValue(thisRef: Any, property: KProperty<*>): Value {
|
||
|
if (storage == null) {
|
||
|
storage = create()
|
||
|
onCreate()
|
||
|
}
|
||
|
return storage!!
|
||
|
}
|
||
|
|
||
|
}
|