Package dev.fritz2.validation

Types

Link copied to clipboard
open class ValidatingStore<D, T, M>(initialData: D, validation: Validation<D, T, M>, validateAfterUpdate: Boolean, id: String) : RootStore<D>

A ValidatingStore is a RootStore which also contains a Validation for its model and by default applies it to every update.

Link copied to clipboard
value class Validation<D, T, M>(validate: (D, T?) -> List<M>)

Encapsulates the logic for validating a given data-model and some optional metadata.

Link copied to clipboard
interface ValidationMessage

Minimal interface for a validation message that exposes the model path for matching relevant sub-model-data and probably relevant UI element representation for showing the message and getting information about the valid state after validation process.

Functions

Link copied to clipboard
fun <M : ValidationMessage> Store<*>.messages(): Flow<List<M>>?

Finds all corresponding ValidationMessages to this Store.

Link copied to clipboard
fun <D, T, M> storeOf(initialData: D, validation: Validation<D, T, M>, id: String = Id.next()): ValidatingStore<D, T, M>

Convenience function to create a simple ValidatingStore without any handlers, etc. The created Store validates its model after every update automatically.

Link copied to clipboard
fun <D, M> validation(validate: MutableList<M>.(Inspector<D>) -> Unit): Validation<D, Unit, M>

Convenience function for creating a Validation instance only accepting model-data by working on a MutableList receiver and using an Inspector for getting the right Inspector.path from sub-models next to the Inspector.data.

fun <D, T, M> validation(validate: MutableList<M>.(Inspector<D>, T?) -> Unit): Validation<D, T, M>

Convenience function for creating a Validation instance accepting model- and metadata by working on a MutableList receiver and using an Inspector for getting the right Inspector.path from sub-models next to the Inspector.data.

Properties

Link copied to clipboard
val <M : ValidationMessage> List<M>.valid: Boolean

Returns true when the list contains no ValidationMessage which is marked with ValidationMessage.isError.

Link copied to clipboard
val <M : ValidationMessage> Flow<List<M>>.valid: Flow<Boolean>

Checks if a Flow of a List of ValidationMessages is valid.