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

need a better API for specifying "null is a valid value" #231

Closed
pixelzoom opened this issue Mar 6, 2019 · 3 comments
Closed

need a better API for specifying "null is a valid value" #231

pixelzoom opened this issue Mar 6, 2019 · 3 comments

Comments

@pixelzoom
Copy link
Contributor

pixelzoom commented Mar 6, 2019

If null is a valid value for a Property, then using type-specific Properties is out of the question, and I have to resort to this boilerplate:

const someProperty = new Property( initialValue, {
  isValidValue:  value => ( value instanceof SomeType || value === null ),
  phetioType: NullableIO( SomeTypeIO )
} );

I see 165 occurrences of regex Property.<.*\|null in PhET code, so this is a common scenario.

Can validator.js and Property APIs support a simple way of specifying that null is a valid value? Something that makes the above boilerplate unnecessary?

@samreid
Copy link
Member

samreid commented Mar 7, 2019

I believe @pixelzoom proposed valueType: [SomeType, null] for cases like that. @zepumph or @pixelzoom does that ring a bell?

@pixelzoom
Copy link
Contributor Author

That rings a bell, but I can't find the issue where I proposed that (if one exists).

@pixelzoom
Copy link
Contributor Author

Ah, here it is: #228 (comment). So I'm going to close this as a duplicate issue.

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