
main.react.StateInstance.kt Maven / Gradle / Ivy
@file:Suppress("NOTHING_TO_INLINE")
package react
import kotlin.reflect.KProperty
// TODO: make external in IR
class StateSetter
private constructor() {
inline operator fun invoke(value: T) {
asDynamic()(value)
}
inline operator fun invoke(noinline transform: (T) -> T) {
asDynamic()(transform)
}
}
/**
* Only works inside [fc]
* @see Hooks and Function Components
*/
// TODO: make external in IR
class StateInstance
private constructor() {
inline operator fun component1(): T = asDynamic()[0]
inline operator fun component2(): StateSetter = asDynamic()[1]
inline operator fun getValue(
thisRef: Nothing?,
property: KProperty<*>,
): T =
asDynamic()[0]
inline operator fun setValue(
thisRef: Nothing?,
property: KProperty<*>,
value: T,
) {
asDynamic()[1](value)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy