-
Notifications
You must be signed in to change notification settings - Fork 18
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
refactor: convert Validator to Class #90
refactor: convert Validator to Class #90
Conversation
ea2357c
to
a514ae3
Compare
I wanted to expose the base import { Validator } from '@ember-decorators/argument';
class SomeValidator extends Validator {} With good enough dead code elimination, it should be safe to support this; we filter out the use of |
a514ae3
to
7bc4852
Compare
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 looks good, I think the classes really clean things up in general, nice job!
This refactors the concept of what a Validator actually is, changing it from a Function into a Class. This allows for co-locating all of the information about how to check a value and format the error message into a single location. The Validator class can be treated as a Monoid, meaning that it can be combined with other instances of itself to build up more complex Validators. Many operations that we supported previously can be thought of as combinations of other Validators, so I thought that formalizing that made sense. With base combinators like `and` and `or`, we can build up some of the type modifiers that we support like `arrayOf` or `oneOf`. All of these can be expressed as Validators, in terms of other Validators.
837c5fb
to
29ddb02
Compare
The "meat" of this change converts the existing Validator implementation into a class. Specifically, Validators are now Monoids that can be combined to create more complex validations:
Note: This will conflict with some of the changes made in #88. I'll refactor whichever pull request lands later so that they're compatible.