class ListenerDelegate<L : Any>(initialValue: L, wrap: (realListener: () -> L) -> L) : ReadWriteProperty<Any?, L>

A property delegate to be used with listeners.

The real listener stored in realListener isn't exposed externally, it's only accessible through the wrapper.

The wrapper is exposed by the getter, and a reference to it can be safely stored long-term.

Setting new listeners via the setter will update the underlying listener, and calls to the wrapper will then be forwarded to the latest realListener that was set.



A function that has to produce the wrapper listener. The listener being wrapped can be referenced by calling the realListener() method. This function always returns the current listener, even if it changes.


Link copied to clipboard
constructor(initialValue: L, wrap: (realListener: () -> L) -> L)


Link copied to clipboard
open operator override fun getValue(thisRef: Any?, property: KProperty<*>): L
Link copied to clipboard
open operator override fun setValue(thisRef: Any?, property: KProperty<*>, value: L)