jwstegemann / fritz2

Easily build reactive web-apps in Kotlin based on flows and coroutines.
https://www.fritz2.dev
MIT License
627 stars 25 forks source link

Improves the validation message filtering and resets the default behaviour #826

Closed Lysander closed 6 months ago

Lysander commented 7 months ago

Motivation

Up to the RC5 / RC6 version of fritz2, the messages()-function on Stores just matched the exact path. This behavior was changed by those release candidates: Right now all messages that matches the exact path, but also all messages machining the sub-path will be collected.

Our experience has shown, that this behavior change was a mistake, as the 80% use case is to collect all messages for an exact path. Most of the time one has dedicated form elements, that fit exactly one property of a model and thus should only show messages for itself. It is very rarely happening, that all messages of a sub-model should be shown all together.

This is why this PR changes again the default behavior, but also introduces a dedicated variant for collecting all sub-model messages with the new messagesOfSubModel()-function.

Also, we expose the messages(filterPredicate: (M) -> Boolean)-function, which both other functions uses internally. You can use this function apply custom filtering to the messages.

Overview

Migration Guide

If you want to stick with the behavior from RC5 up to now, just rename all your messages() calls into messagesOfSubModel() and you are done.

If you have created custom filtering to get the exact match, in order to bypass the behavior, you can simply drop those now.

Reverts introduced behavior from #767 and #761

Lysander commented 7 months ago

Just thinking about, whether subModel might be a more fitting name? So messagesOfSubModel?

Lysander commented 6 months ago

Just thinking about, whether subModel might be a more fitting name? So messagesOfSubModel?

Ok, I have renamed this.