You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most of the current Constraints classes don't lend themselves well to reuse beyond their original goal of validating objects. They validate properties of the parameterized type, but they don't expose those individual validations for reuse. Those turn out to be really handy for letting UIs provide live validation feedback. I explored refactoring these recently. See EventPersistConstraints
overridefunassess(candidate:Event) {
hasUniqueName(candidate.id to candidate.name).getOrThrow()
// brevity
}
val hasUniqueName = constraint<Pair<UUID, String>>(
{ (id, name) -> resource.stream { it.id != id }.noneMatch { it.name == name } },
{ "Name is not unique" }
)
UIs can then reference constraints.hasUniqueName() to and pass in candidate values in order to give the user validation feedback.
This is just an example. There's an obvious performance concern with iterating every record as the user types, so UI would need to implement with care.
The text was updated successfully, but these errors were encountered:
Most of the current Constraints classes don't lend themselves well to reuse beyond their original goal of validating objects. They validate properties of the parameterized type, but they don't expose those individual validations for reuse. Those turn out to be really handy for letting UIs provide live validation feedback. I explored refactoring these recently. See
EventPersistConstraints
UIs can then reference
constraints.hasUniqueName()
to and pass in candidate values in order to give the user validation feedback.This is just an example. There's an obvious performance concern with iterating every record as the user types, so UI would need to implement with care.
The text was updated successfully, but these errors were encountered: