-
Notifications
You must be signed in to change notification settings - Fork 933
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
feat: support self references #443
Conversation
6fdb16a
to
953feee
Compare
Found usage for |
953feee
to
e11cbb7
Compare
Ok, now i understand why Made Only public api change is |
e11cbb7
to
aa19c52
Compare
Three more things:
mixed().when(string(), {then: string().min(5)}) Also possible to omit key for self reference: mixed().when({is: string(), then: string().min(5)})
yup.number().validateSync([]) // will throw
yup.mixed().concat(yup.number()).validateSync([]) // will return [] Even through previous |
Hey thanks for PR it's a bit tough to follow the work here since it seems like it started off as a small code hygiene fix and ended up adding a few features and changing the API. Generally it's be great if we can scope PRs to one change, especially when they change the API so it's easier review and other fixes are blocked behind discussion of unrelated changes. For this can we clearly state wat you are trying add and why it's needed? That will help me contextualize the change while review ig as well as understand whether API changes are needed |
My end goal - support There are 4 different issues:
Currently there are 3 commits in this PR so it is simpler to look at changes. |
aa19c52
to
0f9df92
Compare
Split PR into 3 parts. This PR consist of two commits now and addresses two first issues each with a test. |
Additional major refactor of Reference.js file. Changes:
|
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.
OK so thinking about it, I don't actually think we should continue to support self references in when
. It was support originally as an early hack when lazy
didn't exist yet. The reason when
continues to exist along side lazy
is specifically for when you have interplay between dependencies, i.e. the other fields. As you have seen when
conditions are structured and topo-sorted so that values are processed in the right order. For a self reference that's unneeded.
I also think it may be helpful for me to frame the overall goals for the codebase, since you're (very helpfully) jumping in a lot. yup
should be "intuitive" and easy to use as well as very expressive, and open up when you need complex behavior. It also should be slim, as a browser first validation library. It's size is the major differentiator between joi (as well as async support but they've kinda caught up there). That's not to say i don't want to add new code, but we should consider new code a net negative to start, and justify it. Often it's worth it but we also want to try and trim we can. I mention this not b/c your adding a lot of bulk (your not) but to give some context for when i push back against additional overloads, or certain convenience API shortcuts. Hopethat doesn't sound off putting. I'm glad to have more input on yup 👍
7311c87
to
1104b99
Compare
Out of all source code in this pull request right now self references support take only 10 small lines (other stuff is tests and refactor with features). What are benefits?
Personally, this is (plus lack of |
src/Reference.js
Outdated
this.prefix = prefix; | ||
this.isContext = this.key.indexOf(prefix) === 0; | ||
this.isSelf = this.key === '.'; | ||
if (this.getter && result !== undefined) result = this.getter(result); |
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.
this.getter can't be falsey if the parent check is removed
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.
getter
is falsey if path
is empty (key = prefix + path). So for key "."
path
is empty and so there is no getter.
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.
see comment above ☝️
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.
Now it is:
if (this.getter) result = this.getter(result || {});
Is there any problem with that?
Those are good reasons 👍 I will say tho that API parity with I agree with you that declarative affordances like In this case i think you're right the code is minimal, and the api is nicer, and easy to support. |
ccd27f7
to
217e347
Compare
33816d4
to
d05313c
Compare
d05313c
to
e4244b7
Compare
key
cannot be a function sincevalidateName
ensures that it is a string.isSelf
is not used anywhere andkey="."
isn't supported byproperty-expr
getter.For working self references i opened pull request in
property-expr
to support empty string path. (currentlygetter("")
works, butgetter("", true)
which is used in Reference.js throws)