RootStore

open class RootStore<T>(initialData: T, id: String) : Store<T>

A Store can be initialized with a given value. Use a RootStore to "store" your model and create SubStores from here.

Parameters

initialData

: the first current value of this Store

id

: the id of this store. ids of SubStores will be concatenated.

Constructors

RootStore
Link copied to clipboard
js
fun <T> RootStore(initialData: T, id: String = "")
: the first current value of this Store

Functions

enqueue
Link copied to clipboard
js
open suspend override fun enqueue(update: QueuedUpdate<T>)
in a RootStore an Update is handled by applying it to the internal StateFlow.
errorHandler
Link copied to clipboard
js
open fun errorHandler(exception: Throwable, oldValue: T): T
Default error handler printing the error to console and keeping the previous value.
handle
Link copied to clipboard
js
open fun handle(errorHandler: ErrorHandler<T> = ::errorHandler, execute: suspend (T) -> T): SimpleHandler<Unit>
Factory method to create a SimpleHandler that does not take an Action
open fun <A> handle(errorHandler: ErrorHandler<T> = ::errorHandler, execute: suspend (T, A) -> T): SimpleHandler<A>
Factory method to create a SimpleHandler mapping the actual value of the Store and a given Action to a new value.
handleAndEmit
Link copied to clipboard
js
open fun <E> handleAndEmit(errorHandler: ErrorHandler<T> = ::errorHandler, execute: suspend FlowCollector<E>.(T) -> T): 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(errorHandler: ErrorHandler<T> = ::errorHandler, execute: suspend FlowCollector<E>.(T, A) -> T): EmittingHandler<A, E>
Factory method to create a EmittingHandler taking an action-value and the current store value to derive the new value.
handledBy
Link copied to clipboard
js
open infix fun <E : Event, X : Element> DomListener<E, X>.handledBy(handler: Handler<Unit>)
Connects Events to a Handler.
open infix fun <E : Event> WindowListener<E>.handledBy(handler: Handler<Unit>)
Connects Events to a Handler.
open infix fun <A> Flow<A>.handledBy(handler: Handler<A>)
Connects a Flow to a Handler.
sub
Link copied to clipboard
js
fun <X> sub(lens: Lens<T, X>): SubStore<T, T, X>
create a SubStore that represents a certain part of your data model.
syncBy
Link copied to clipboard
js
open fun syncBy(handler: Handler<T>)
calls a handler on each new value of the Store
open fun syncBy(handler: Handler<Unit>)
calls a handler on each new value of the Store
syncWith
Link copied to clipboard
js
open fun <I> syncWith(socket: Socket, resource: Resource<T, I>)

Properties

current
Link copied to clipboard
js
open override val current: T
Represents the current data of this RootStore.
data
Link copied to clipboard
js
open override val data: Flow<T>
Emits a Flow with the current data of this RootStore.
id
Link copied to clipboard
js
open override val id: String
: the id of this store.
job
Link copied to clipboard
js
open override val job: Job
Job used as parent job on all coroutines started in Handlers in the scope of this Store
update
Link copied to clipboard
js
open override val update: SimpleHandler<T>
a simple SimpleHandler that just takes the given action-value as the new value for the Store.

Extensions

sub
Link copied to clipboard
js
fun <T, I> RootStore<List<T>>.sub(element: T, id: IdProvider<T, I>): SubStore<List<T>, List<T>, T>
creates a SubStore using a RootStore as parent using a given IdProvider.
fun <T> RootStore<List<T>>.sub(index: Int): SubStore<List<T>, List<T>, T>
creates a SubStore using a RootStore as parent using the index in the list (do not use this, if you want to manipulate the list itself (add or move elements, filter, etc.).