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

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

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


abstract class AlwaysProducer : Producer() {

    companion object {

        fun  create(getter: () -> T): Producer =
                object : AlwaysProducer() {
                    override val value: T
                        get() = getter.invoke()
                }

        fun  create(value: T): Producer =
                object : AlwaysProducer() {
                    override val value = value
                }

    }

    protected abstract val value: T

    protected fun onValueChanged() =
            call(value)

    override fun onAttached(listener: (T) -> Unit) {
        super.onAttached(listener)
        listener.invoke(value)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy