SubStore

class SubStore<P, D>(val parent: Store<P>, lens: Lens<P, D>) : Store<D>

A Store that is derived from a parent Store mapping its data in both ways by a given Lens.

Constructors

Link copied to clipboard
constructor(parent: Store<P>, lens: Lens<P, D>)

Properties

Link copied to clipboard
open override val current: D

represents the current value of the Store

Link copied to clipboard
open override val data: Flow<D>

the current value of the Store is derived from the data of it's parent using the given Lens.

Link copied to clipboard
open override val id: String

defines how to infer the id of the sub-part from the parent's id.

Link copied to clipboard
open override val job: Job

Job used as parent job on all coroutines started in Handlers in the scope of this Store

Link copied to clipboard
val parent: Store<P>
Link copied to clipboard
open override val path: String

defines how to infer the id of the sub-part from the parent's id.

Link copied to clipboard
open override val update: SimpleHandler<D>

a simple SimpleHandler that just takes the given action-value as the new value for the Store.

Functions

Link copied to clipboard
open suspend override fun enqueue(update: Update<D>)

Since a SubStore is just a view on a parent holding the real value, it forwards the Update to it, using it's Lens to transform it.

Link copied to clipboard
open override fun errorHandler(cause: Throwable)

Default error handler printing the error to console.

Link copied to clipboard
open fun handle(execute: suspend (D) -> D): SimpleHandler<Unit>

Factory method to create a SimpleHandler that does not take an Action

open fun <A> handle(execute: suspend (D, A) -> D): SimpleHandler<A>

Factory method to create a SimpleHandler mapping the actual value of the Store and a given Action to a new value.

Link copied to clipboard
open fun <E> handleAndEmit(execute: suspend FlowCollector<E>.(D) -> D): EmittingHandler<Unit, E>

factory method to create an EmittingHandler that does not take an action in it's execute-lambda.

open fun <A, E> handleAndEmit(execute: suspend FlowCollector<E>.(D, A) -> D): EmittingHandler<A, E>

Factory method to create a EmittingHandler taking an action-value and the current store value to derive the new value. An EmittingHandler is a Flow by itself and can therefore be connected to other SimpleHandlers even in other Stores.

Link copied to clipboard
open fun <E> handleOnlyEmit(execute: suspend FlowCollector<E>.(D) -> Unit): EmittingHandler<Unit, E>

factory method to create an EmittingHandler taking the current store value but does not derive a new value from it. The actual value is just passed through, so it is all about dealing with some side effect by calling the FlowCollector.emit function from within the execute parameter.

open fun <A, E> handleOnlyEmit(execute: suspend FlowCollector<E>.(D, A) -> Unit): EmittingHandler<A, E>

factory method to create an EmittingHandler taking an action-value and the current store value but does not derive a new value from both. The actual value is just passed through, so it is all about dealing with some side effect by calling the FlowCollector.emit function from within the execute parameter.

Link copied to clipboard
fun <D> Store<D>.history(capacity: Int = 0, initialEntries: List<D> = emptyList(), job: Job = this.job, synced: Boolean = true): History<D>

factory-method to create a History synced with the given Store, so that each update is automatically stored in history.

Link copied to clipboard
open fun <X> map(lens: Lens<D, X>): Store<X>

Creates a new Store that contains data derived by a given Lens.

Link copied to clipboard
fun <P, T> Store<P?>.map(lens: Lens<P & Any, T>): Store<T>

on a Store of nullable data this creates a Store with a nullable parent and non-nullable value. It can be called using a Lens on a non-nullable parent (that can be created by using the @Lenses-annotation), but you have to ensure, that the resulting Store is never used, when it's parent's value is null. Otherwise, a NullPointerException is thrown.

Link copied to clipboard
fun <D, I> Store<List<D>>.mapByElement(element: D, idProvider: IdProvider<D, I>): Store<D>

Creates a new Store containing the element for the given element and idProvider from the original Store's List.

Link copied to clipboard
fun <D> Store<List<D>>.mapByIndex(index: Int): Store<D>

Creates a new Store containing the element for the given index from the original Store's List

Link copied to clipboard
fun <K, V> Store<Map<K, V>>.mapByKey(key: K): Store<V>

Creates a new Store containing the corresponding value for the given key from the original Store's Map.

Link copied to clipboard
fun <T> Store<T?>.mapNull(default: T): Store<T>

Creates a new Store from a nullable parent store that either contains the original value or a given default value if the original value was null.

Link copied to clipboard
fun <T> Store<T>.mapNullable(placeholder: T): Store<T?>

Creates a new Store from a non-nullable parent store that either contains the original value or null if its value matches the given placeholder.

Link copied to clipboard
fun <M : ValidationMessage> Store<*>.messages(): Flow<List<M>>?

Finds all exactly corresponding ValidationMessages to this Store, which means all messages, which have exactly the same path as the Store.

fun <M : ValidationMessage> Store<*>.messages(filterPredicate: (M) -> Boolean): Flow<List<M>>?

Finds all corresponding ValidationMessages to this Store which satisfy the filterPredicate-expression.

Link copied to clipboard

Finds all corresponding ValidationMessages to this Store, which means all messages, that fit exactly with their path or which are sub-elements of this Stores data model.