All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.hnau.jutils.producer.StateProducerSimple.kt Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package ru.hnau.jutils.producer

import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty


class StateProducerSimple(
        initialState: T? = null
) : StateProducer(
        initialState = initialState
), ReadWriteProperty {

    val currentState: T?
        get() = state

    fun updateState(state: T?) = update(state)
    fun updateStateIfChanged(state: T?) = updateIfChanged(state)
    fun clearState() = clear()

    override operator fun getValue(thisRef: Any, property: KProperty<*>) =
            currentState

    override operator fun setValue(thisRef: Any, property: KProperty<*>, value: T?) =
            updateStateIfChanged(value)

}

fun StateProducerSimple.invert() =
        updateState((currentState ?: false).not())





© 2015 - 2024 Weber Informatics LLC | Privacy Policy