RootStore

open class RootStore<D>(initialData: D, val id: String = Id.next()) : Store<D>

A Store can be initialized with a given value.

Parameters

initialData

first current value of this Store

id

id of this Store. Ids of derived Stores will be concatenated.

Constructors

Link copied to clipboard
fun <D> RootStore(initialData: D, id: String = Id.next())

Functions

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

in a RootStore an Update is handled by applying it to the internal StateFlow.

Link copied to clipboard
open 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 infix fun <A> Flow<A>.handledBy(handler: Handler<A>)

Connects a Flow to a Handler.

open infix fun <A> Flow<A>.handledBy(execute: suspend (A) -> Unit): Job
open infix fun <E : Event> Flow<E>.handledBy(execute: suspend (E) -> Unit): Job

Connects a Flow to a suspendable execute function.

open infix fun <E : Event> Flow<E>.handledBy(handler: Handler<Unit>)

Connects Events to a Handler.

Link copied to clipboard
open operator fun Handler<Unit>.invoke()
open operator fun <A> Handler<A>.invoke(data: A)

Calls this handler exactly once.

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

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

Properties

Link copied to clipboard
open override val current: D

Represents the current data of this Store.

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

Emits a Flow with the current data of this Store. The Flow internal data is only changed, when the value differs from the last one to avoid calculations and updates that are not necessary.

Link copied to clipboard
open override val id: String
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
open override val path: String

Path of this Store derived from the underlying model. Paths of depending Stores are concatenated and separated by a dot.

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.

Inheritors

Link copied to clipboard

Extensions

Link copied to clipboard
fun <D> Store<D>.history(capacity: Int = 0, initialEntries: List<D> = emptyList(), 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
fun <M : ValidationMessage> Store<*>.messages(): Flow<List<M>>?

Finds all corresponding ValidationMessages to this Store.

Link copied to clipboard
fun <T> Store<T?>.orDefault(default: 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 provide a default value. When updating the value of the resulting Store to this default value, null is used instead updating the parent. When this Store's value would be null according to it's parent's value, the default value will be used instead.

Link copied to clipboard
fun <D, I> Store<List<D>>.sub(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.

fun <D> Store<List<D>>.sub(index: Int): Store<D>

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

fun <K, V> Store<Map<K, V>>.sub(key: K): Store<V>

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

fun <P, T> Store<P?>.sub(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.