Router

open class Router<T>(defaultRoute: Route<T>) : Store<T>

Router register the event-listener for hashchange-event and handles route-changes. Therefore, it uses a Route object which can Route.serialize and Route.deserialize the given type.

Parameters

T

type to marshal and unmarshal

Constructors

Router
Link copied to clipboard
js
fun <T> Router(defaultRoute: Route<T>)
type to marshal and unmarshal

Functions

enqueue
Link copied to clipboard
js
open suspend override fun enqueue(update: QueuedUpdate<T>)
abstract method defining, how this Store handles an Update
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, X : Element> DomListener<E, X>.handledBy(execute: suspend (E) -> Unit): Job
Connects a Flow to a suspendable execute function.
open infix fun <E : Event> WindowListener<E>.handledBy(handler: Handler<Unit>)
Connects Events to a Handler.
open infix fun <E : Event> WindowListener<E>.handledBy(execute: suspend (E) -> Unit): Job
Connects a Flow to a suspendable execute function.
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
Connects a Flow to a suspendable execute function.
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 Flow representing the current value of the Store.
id
Link copied to clipboard
js
open override val id: String
id of this Store.
job
Link copied to clipboard
js
open override val job: Job
Job for launching coroutines in.
navTo
Link copied to clipboard
js
open val navTo: SimpleHandler<T>
Navigates to the new given route provided as T.
path
Link copied to clipboard
js
open override val path: String
Path of this Store derived from the underlying model.
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.

Inheritors

MapRouter
Link copied to clipboard