observe
protected fun <TValue> observe(pathToObserve: Path, updateState: UpdateStateFn<TValue, TState>): PropertyDelegateProvider<StatefulValidation<T, TState>, ReadOnlyProperty<StatefulValidation<T, TState>, Observer<TValue, TState>>>(source)
protected fun <TValue> observe(pathToObserve: String, updateState: UpdateStateFn<TValue, TState>): PropertyDelegateProvider<StatefulValidation<T, TState>, ReadOnlyProperty<StatefulValidation<T, TState>, Observer<TValue, TState>>>(source)
Function used to observe the path pathToObserve and update the validation state via updateState whenever an event with a path matching pathToObserve occurs.
If an event path matches multiple observers, only the first observer will be called.
It should be used as follows:
private val observer by observe<Type>(path) { state, event ->
when (event) {
is ValueEvent.Init<Type> -> // Compute new state
is ValueEvent.Change<Type> -> // Compute new state
is ValueEvent.Destroy<Type> -> // Compute new state
// These events only occur when observing a collection:
is ValueEvent.Add<Type, *> -> // Compute new state
is ValueEvent.Remove<Type, *> -> // Compute new state
}
}Content copied to clipboard
The provided function must return the new validation state which, unless it hasn't changed, should be different (equals-wise) from the previous validation state (as such, when using an object as state, a new instance should be returned when the state is updated). If the new state differs from the old one (using equals), the value will need to be revalidated by the form manager using validateFromState.