SubStore

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

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

Constructors

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

Functions

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

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.

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>): SubStore<D, X>

create a SubStore that represents a certain part of your data model.

Link copied to clipboard
open fun <D, I> Store<D>.syncWith(socket: Socket, resource: Resource<D, I>)

Syncs a Store by via a Websockets connection.

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 SubStore 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.