
walkmc.Property.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of walk-server Show documentation
Show all versions of walk-server Show documentation
A spigot fork to kotlin structure and news.
package walkmc
import kotlin.properties.*
import kotlin.reflect.*
/**
* Represents a property utility class.
*/
public data class Property(
val property: KProperty<*>,
val oldValue: T,
val newValue: T,
)
/**
* Returns a property delegate for a read/write property that calls a specified
* callback function when changed.
*/
public inline fun observable(
initialValue: T,
crossinline block: Property.() -> Unit,
): ReadWriteProperty =
Delegates.observable(initialValue) { property, oldValue, newValue ->
block(Property(property, oldValue, newValue))
}
/**
* Returns a property delegate for a read/write property that calls a specified
* callback function when changed, allowing the callback to veto the modification.
*/
public inline fun vetoable(
initialValue: T,
crossinline block: Property.() -> Boolean,
): ReadWriteProperty =
Delegates.vetoable(initialValue) { property, oldValue, newValue ->
block(Property(property, oldValue, newValue))
}
/**
* Returns a property delegate for a read/write property with a non-null value
* that is initialized not during object construction time but at a later time.
* Trying to read the property before the initial value has been assigned results in an exception.
*/
public fun notnull() = Delegates.notNull()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy