-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Validation approach #570
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jamowei
added
api breaking
Forces client sources to change
api improvement
enhancement
New feature or request
labels
Jan 20, 2022
Closed
Opened up a ticket at Jetbrains Youtrack: https://youtrack.jetbrains.com/issue/KT-50897 |
jamowei
force-pushed
the
jamowei/newValidation
branch
from
January 24, 2022 10:46
46e9b77
to
9a6e329
Compare
ghost
suggested changes
Jan 27, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some proposals for the API docs.
Besides this looks really good! I hardly can wait to use this :-)
I have some proposals for the release notes too. We should talk about those afterwards.
- add / change some API docs - remove obsolete files - remove obsolete module (core/jvmMain)
# Conflicts: # core/src/jsMain/kotlin/dev/fritz2/binding/store.kt # core/src/jsMain/kotlin/dev/fritz2/binding/substores.kt
ghost
self-requested a review
January 31, 2022 10:33
ghost
previously approved these changes
Jan 31, 2022
ghost
approved these changes
Feb 1, 2022
This pull request was closed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, you need to specify a
Validation
for your data-model. Therefore, you can use one of the two new global convenience functions:These functions are available in the
commonMain
source set, so you can create yourValidation
object right next to your data classes to keep them together. Example:Then you can call your
Validation
everywhere (e.g. JVM- or JS-site) to get a list of messages which shows if your model is valid or not. We recommend extending your validation messages from theValidationMessage
interface. Then your validation message type must implement thepath
which is important for matching your message to the corresponding attribute of your data-model and theisError
value which is needed to know when your model is valid or not:New ValidatingStore
We introduce a new type of
Store
which we callValidatingStore
. ThisStore
has the same properties as aRootStore
and additionally aValidation
which it uses to validate the stored model. With these additional information you get next to your knowndata
flow also amessages
flow which you can use to render out your list of validation messages. Furthermore, you can decide on store creation if you want to automatically validate your model after an update to your store takes place. Then you have to set thevalidateAfterUpdate
flag and the flow of messages gets accordingly updated. Otherwise, you can call thevalidate(data: D, metadata: T? = null)
function inside your own handlers to update the list of messages by your own. For cases, you want to reset your validation state to an empty list or to a specific list of messages, you can use theresetMessages(messages: List<M> = emptyList())
function. Example: