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

commonMain.org.brightify.hyperdrive.property.impl.DeferredToImmediateObservablePropertyWrapper.kt Maven / Gradle / Ivy

There is a newer version: 0.1.159
Show newest version
package org.brightify.hyperdrive.property.impl

import org.brightify.hyperdrive.CancellationToken
import org.brightify.hyperdrive.property.DeferredObservableProperty
import org.brightify.hyperdrive.property.ObservableProperty
import org.brightify.hyperdrive.utils.Optional

internal class DeferredToImmediateObservablePropertyWrapper(
    private val initialValue: T,
    private val wrapped: DeferredObservableProperty,
): ObservableProperty, DeferredObservableProperty.Listener {
    private val listeners = ValueChangeListenerHandler(this)

    override var value: T = initialValue
        private set

    init {
        wrapped.addListener(this)
    }

    override fun valueDidChange(oldValue: Optional, newValue: T) {
        listeners.runNotifyingListeners(newValue) {
            value = it
        }
    }

    override fun addListener(listener: ObservableProperty.Listener): CancellationToken = listeners.addListener(listener)

    override fun removeListener(listener: ObservableProperty.Listener) = listeners.removeListener(listener)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy