Skip to content
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

Nested composed validators do not curry as expected. #54

Open
jaridmargolin opened this issue May 10, 2017 · 2 comments
Open

Nested composed validators do not curry as expected. #54

jaridmargolin opened this issue May 10, 2017 · 2 comments

Comments

@jaridmargolin
Copy link

Nested composed validators do not curry as expected.

* This may just be a misunderstanding of the lib is intended to work.

Expected:

// imagine I have created a validator `containsNoNumbers`
const isName = composeValidators(hasLengthBetween(2, 32), containsNoNumbers)
composeValidators(isRequired, isName)('First Name')
composeValidators(isRequired, isName)('Last Name')

isRerquired works as expected and allows the field to propagate through. isName however always returns a function. I can fix the issue by doing something like:

const isName = composeValidators(hasLengthBetween(2, 32), containsNoNumbers)
composeValidators(isRequired, isName('First Name'))('First Name')
composeValidators(isRequired, isName('Last Name'))('Last Name')

but it seems as though the composed validator should work exactly the same as a created validator.

The composed validator is also curried and takes the same arguments as an individual validator made with createValidator.

@jfairbank
Copy link
Owner

Hey, @jaridmargolin.

Sorry for the misunderstanding. I originally wrote composeValidators with validators created via createValidator in mind, so I never thought about the nested way you're trying to use it here. That being said, I don't see any reason why we can't support your use case too.

I'm swamped at the moment, so I may not be able to hop on fixing this immediately. You're welcome to open a PR if you like, though. Just let me know.

Thanks!

@jaridmargolin
Copy link
Author

I was poking around in the source code but it wasn't immediately clear to me where / what the patch would look like. If I have some more time to dig into a fix, I will.

Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants