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

Have validators reflect that values are optional by default. #140

Closed
mthadley opened this issue Aug 1, 2016 · 2 comments
Closed

Have validators reflect that values are optional by default. #140

mthadley opened this issue Aug 1, 2016 · 2 comments
Assignees

Comments

@mthadley
Copy link

mthadley commented Aug 1, 2016

Given the following configuration:

MyComponent.PROPS = {
  foo: Config.number().isRequired(),
  bar: Config.number()
};

It seems that bar should be considered optional, since we omitted the isRequired call. However, validator warnings will still be thrown if a value is not passed.

It seems like we may want something like Config.number() to be implicitly Config.maybe(Config.number()).

Any thoughts on this would be greatly appreciated, thanks!

@mairatma
Copy link
Contributor

mairatma commented Aug 1, 2016

That makes sense, if a value is not listed as required than it should behave as optional, otherwise it'll be very confusing. Your suggestion of having validators work as maybe by default is a good one. In this case we may actually not need to expose Config.maybe at all then, since that's always implied.

@mairatma mairatma self-assigned this Aug 1, 2016
mairatma added a commit that referenced this issue Aug 2, 2016
Now, to stop accepting those the "required" config should be used instead (via the `Config` module).

Also, the `shapeOf` validator can receive config objects, for specifying not only the validator but also if it should be required or not. If this information isn't given, any property in the defined shape will be assumed to be optional.
@mairatma
Copy link
Contributor

mairatma commented Aug 2, 2016

This is now available in version 2.1.3.

@mairatma mairatma closed this as completed Aug 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants