-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
validate 🎁🎅 #308
base: main
Are you sure you want to change the base?
validate 🎁🎅 #308
Conversation
Signed-off-by: dotnetCarpenter <[email protected]>
index.js
Outdated
// TODO: figure what propPath really is | ||
type: result.value.propPath.length > 0 | ||
? type.types[result.value.propPath[0]].name | ||
: type.name, |
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.
@davidchambers this part I'm really not sure about. The idea is to get the name of the Type that is invalid for nested types. I haven't seen any propPath
that didn't exactly contain ['$1']
but I'm sure that there are cases.
This commit also marks the first use of Z (sanctuary-type-classes), which should open up for many of the code reductions we already know from Sanctuary. Added one more test for Types with properties/keys, without a name, are missing and the value is null/undefined.
2ea1aa2
to
d404784
Compare
index.js
Outdated
return Left ({ | ||
error: 'WrongValue', | ||
// TODO: figure out what propPath really is | ||
type: p.result.value.propPath.length > 0 | ||
? p.type.types[p.result.value.propPath[0]].name | ||
: p.type.name, | ||
name: p.name, | ||
value: p.value | ||
}); |
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.
@davidchambers this part I'm really not sure about. The idea is to get the name of the Type that is invalid for nested types. I haven't seen any propPath
that didn't exactly contain ['$1']
but I'm sure that there are cases.
Since a value can have 3 distinct outcomes, I think that it would make the code more readable to encode that as a sum type.
@davidchambers How do you feel about requiring daggy in sanctuary-def? |
This commit adds two extra functions, a curried `map` and `lefts`. There is plenty of room for optimization but we should validate the concept with a simple example application before optimizing.
There is plenty of room for optimization but before I do any of that, I want to create a simple form validation example using the new @davidchambers I really need you help to understand |
Signature
Example
Task before merge
$.validate
to confirm design. WIP sanctuary-def-validate$.validate
for readability while keeping an eye on performanceDescription
Takes a type, and any value. Returns
Right a
ifthe value is a member of the type;
Left (Array ValidationError)
for each propertythat is invalid. The first index in a
Left
arrayis always named
$$
, which refers to the entire value.Custom Type Example
Ref: #274