Clean up, release v. 1.0.0

This commit is contained in:
2022-01-14 16:00:46 +01:00
parent 5bfb23305a
commit dcd7b4362b
5 changed files with 249 additions and 180 deletions

View File

@@ -0,0 +1,35 @@
package nl.astraeus.komp
import kotlin.reflect.KProperty
class StateDelegate<T>(
val komponent: Komponent,
initialValue: T
) {
var value: T = initialValue
operator fun getValue(
thisRef: Any?,
property: KProperty<*>
): T {
return value
}
operator fun setValue(
thisRef: Any?,
property: KProperty<*>,
value: T
) {
if (this.value?.equals(value) != true) {
this.value = value
komponent.requestUpdate()
}
}
}
inline fun <reified T> Komponent.state(
initialValue: T
): StateDelegate<T> = StateDelegate(
this,
initialValue
)