Conversation
Signed-off-by: dotnetCarpenter <jon.ronnenberg@gmail.com>
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.
@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.
@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
$.validateto confirm design. WIP sanctuary-def-validate$.validatefor readability while keeping an eye on performanceDescription
Takes a type, and any value. Returns
Right aifthe value is a member of the type;
Left (Array ValidationError)for each propertythat is invalid. The first index in a
Leftarrayis always named
$$, which refers to the entire value.Custom Type Example
Ref: #274