SubStore

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

A Store that is derived from your RootStore or another SubStore that represents a part of the data-model of it's parent. Use the .sub-factory-method on the parent Store to create it.

Constructors

SubStore
Link copied to clipboard
js
fun <P, T> SubStore(parent: Store<P>, lens: Lens<P, T>)

Functions

enqueue
Link copied to clipboard
js
open suspend override fun enqueue(update: QueuedUpdate<T>)
Since a SubStore is just a view on a RootStore holding the real value, it forwards the Update to it, using it's Lens to transform it.
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
open fun <X> sub(lens: Lens<T, X>): SubStore<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 value of the Store
data
Link copied to clipboard
js
open override val data: Flow<T>
the current value of the SubStore is derived from the data of it's parent using the given Lens.
id
Link copied to clipboard
js
open override val id: String
defines how to infer the id of the sub-part from the parent's id.
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
parent
Link copied to clipboard
js
val parent: Store<P>
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.