ViewableList

class ViewableList<T : Any>(storage: MutableList<T> = mutableListOf()) : IMutableViewableList<T>

Constructors

Link copied to clipboard
constructor(storage: MutableList<T> = mutableListOf())

Properties

Link copied to clipboard
open override val change: Signal<IViewableList.Event<T>>
Link copied to clipboard
open val changing: Boolean
Link copied to clipboard
open override val size: Int

Functions

Link copied to clipboard
open override fun add(element: T): Boolean
open override fun add(index: Int, element: T)
Link copied to clipboard
open override fun addAll(elements: Collection<T>): Boolean
open override fun addAll(index: Int, elements: Collection<T>): Boolean
Link copied to clipboard
fun <T> MutableCollection<T>.addUnique(lifetime: Lifetime, value: T)
Link copied to clipboard
open override fun advise(lifetime: Lifetime, handler: (IViewableList.Event<T>) -> Unit)

Adds an event subscription. Every time an event occurs, the handler is called, receiving an instance of the event. The subscription is removed when the given lifetime expires.

Link copied to clipboard
fun IVoidSource.advise(lifetime: Lifetime, handler: () -> Unit)
Link copied to clipboard
open fun adviseAddRemove(lifetime: Lifetime, handler: (AddRemove, Int, T) -> Unit)

Adds a subscription to additions and removals of list elements. When a list element is updated, the handler is called twice: to report the removal of the old element and the addition of the new one.

Link copied to clipboard
fun <T> ISource<T>.adviseEternal(handler: (T) -> Unit)

Adds an event subscription that never gets removed.

Link copied to clipboard
fun <T : Any> ISource<T?>.adviseNotNull(lifetime: Lifetime, handler: (T) -> Unit)

Adds an event subscription that filters out null values.

Link copied to clipboard
fun <T : Any> ISource<T?>.adviseNotNullOnce(lifetime: Lifetime, handler: (T) -> Unit): LifetimeDefinition

Executes handler exactly once when the source fires an event with a non-null value, then terminates the subscription

Link copied to clipboard
fun <T> ISource<T>.adviseOnce(lifetime: Lifetime, handler: (T) -> Unit)

Executes handler exactly once then terminates the subscription

Link copied to clipboard
fun <T> ISource<T>.adviseSuspend(lifetime: Lifetime, scheduler: IScheduler, handler: suspend (T) -> Unit)
fun <T> ISource<T>.adviseSuspend(lifetime: Lifetime, context: CoroutineContext, handler: suspend (T) -> Unit)
Link copied to clipboard
fun <T> ISource<T>.adviseUntil(lifetime: Lifetime, handler: (T) -> Boolean)

Holds subscription until handler returns true or lifetime is terminated

Link copied to clipboard
fun <T> ISource<T>.adviseWithPrev(lifetime: Lifetime, handler: (prev: Maybe<T>, cur: T) -> Unit)
Link copied to clipboard
fun <T> ISource<T>.asProperty(defaultValue: T): IPropertyView<T>
Link copied to clipboard
open override fun clear()
Link copied to clipboard
open operator override fun contains(element: T): Boolean
Link copied to clipboard
open override fun containsAll(elements: Collection<T>): Boolean
Link copied to clipboard
Link copied to clipboard
fun <T> ISource<T>.filter(f: (T) -> Boolean): ISource<T>
Link copied to clipboard

fun <T> ISource<T>.flowInto(lifetime: Lifetime, target: ISignal<T>)

Whenever a change happens in this source, fires a change in the target signal of the same type.

fun <TSrc, TDst> ISource<TSrc>.flowInto(lifetime: Lifetime, target: IMutablePropertyBase<TDst>, tf: (TSrc) -> TDst)

Whenever a change happens in this source, changes the target property of the same type.

fun <TSource, TTarget> ISource<TSource>.flowInto(lifetime: Lifetime, target: ISignal<TTarget>, tf: (TSource) -> TTarget)

Whenever a change happens in this source, fires a change in the target signal obtained by running the given tf function.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open operator override fun get(index: Int): T
Link copied to clipboard
open override fun indexOf(element: T): Int
Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
open operator override fun iterator(): MutableIterator<T>
Link copied to clipboard
open override fun lastIndexOf(element: T): Int
Link copied to clipboard
open override fun listIterator(): MutableListIterator<T>
open override fun listIterator(index: Int): MutableListIterator<T>
Link copied to clipboard
fun <T, R> ISource<T>.map(f: (T) -> R): ISource<R>

Returns a new source which remaps events happening in this source using the given function f.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun <T : Any> ISource<T?>.nextNotNullValue(): T
Link copied to clipboard
fun <T : Any> ISource<T?>.nextNotNullValueAsync(lifetime: Lifetime): Deferred<T>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun <T> ISource<T>.nextValue(condition: (T) -> Boolean = { true }): T
Link copied to clipboard
fun <T> ISource<T>.nextValueAsync(lifetime: Lifetime, condition: (T) -> Boolean = { true }): Deferred<T>
Link copied to clipboard
open override fun remove(element: T): Boolean
Link copied to clipboard
open override fun removeAll(elements: Collection<T>): Boolean
Link copied to clipboard
open override fun removeAt(index: Int): T
Link copied to clipboard
fun removeRange(fromIndex: Int, toIndex: Int)
Link copied to clipboard
fun <T> List<T>?.restOrNull(): List<T>?
Link copied to clipboard
open override fun retainAll(elements: Collection<T>): Boolean
Link copied to clipboard
open operator override fun set(index: Int, element: T): T
Link copied to clipboard
open override fun subList(fromIndex: Int, toIndex: Int): MutableList<T>
Link copied to clipboard
fun sync(newValues: Collection<T>): Boolean

Synchronizes the viewable list by adding missing elements and removing unmatched elements. If the order of equal values is not changed, then they won't be modified. However, even if equal elements exist in both lists, but order is swapped, then they will be removed and re-added to satisfy the new values order. It helps drastically reduce the number of change events if the collection is unmodified at all or just a few elements are changed compared to the classical approach with 'clear' and 'addAll'.

Link copied to clipboard
fun <T : Any> ISource<T>.throttleLast(timeout: Duration, scheduler: IScheduler): ISource<T>
Link copied to clipboard
Link copied to clipboard
open override fun view(lifetime: Lifetime, handler: (Lifetime, Pair<Int, T>) -> Unit)

Adds a subscription to changes of the contents of the list.

open fun view(lifetime: Lifetime, handler: (Lifetime, Int, T) -> Unit)

Adds a subscription to changes of the contents of the list, receiving the index and value as separate parameters.

Link copied to clipboard

Returns a property which evaluates to the last element of the list and is updated as elements are added to the list or removed from it.

Link copied to clipboard
fun <T : Any> IViewable<T?>.viewNotNull(lifetime: Lifetime, handler: (Lifetime, T) -> Unit)

Adds a subscription to changes to this viewable's contents and filters out null values. The subscription is removed when the given lifetime expires.

Link copied to clipboard
fun IViewable<Boolean>.whenFalse(lifetime: Lifetime, action: (Lifetime) -> Unit)

Executes the given action every time the value of the property changes to false.

Link copied to clipboard
fun IViewable<Boolean>.whenTrue(lifetime: Lifetime, action: (Lifetime) -> Unit)

Executes the given action every time the value of the property changes to true.