common / com.schibsted.account.common.lib / ObservableField

ObservableField

class ObservableField<T>

Allows to reactively observe value and its changes. Emitted values are guaranteed to be distinct.

Types

Observer

interface Observer<T>

Interface for value observers.

Single

interface Single<T> : ObservableField.Observer<T>

Interface for value observers that are supposed to be invoked only once after a value change. Note, if an Single is added to ObservableField with flag notifyInitially = true, it will be called immediately AND it will be called again after a value change.

Constructors

<init>

ObservableField(initialValue: T)

Allows to reactively observe value and its changes. Emitted values are guaranteed to be distinct.

Properties

value

var value: T

Value to be observed.

Functions

addListener

fun addListener(listener: ObservableField.Observer<T>, notifyInitially: Boolean = false): Unit

Adds an observer for the value. If notifyInitially = true, it will be called immediately with the currently existing value.

fun addListener(single: Boolean = false, notifyInitially: Boolean = false, lambda: (T) -> Unit): ObservableField.Observer<T>

Adds lambda as an observer for the value. If notifyInitially = true, it will be called immediately with the currently existing value. If single = true, the observer will be automatically removed after the first change of the value.

hasObservers

fun hasObservers(): Boolean

Returns true if the observed value has active observers.

removeListener

fun removeListener(listener: ObservableField.Observer<T>): Unit

Removes an observer. Removed observers will not be notified any more.