-
Notifications
You must be signed in to change notification settings - Fork 8
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
Use validator instead of assertInstanceOf #226
Comments
Proposed changes: ObjectIO constructor: // Use the validator defined on the constructor to make sure the instance is valid
assert && validate( instance, this.constructor.validator ); phetioInherit: assert && assert( staticProperties, 'static properties must be defined' );
assert && assert( staticProperties.validator, 'validator must be provided' );
ValidatorDef.validateValidator( staticProperties.validator ); Then we can add We would need a nice syntax to check for toStateObject/fromStateObject as well, not sure what that will be. |
Yes the code should have that. I thought that, I thought that this was added in #204 though. Everything recommended above sounds great. |
I don't think this approach will work because of a circularity problem in loading these modules. Typically we reference the IO type from the core type, and use namespace to get the core type from the IO type. However, IO type is loaded first (since it is a dependency) and the core type doesn't exist at that time. |
Why would it not work to consistently use the name space to reference the core type from the io type? Since all the usages are nested in the io type constructor, which won't be called until the core type has been loaded to the name space? |
@zepumph and I discussed it, and considered lazily creating the validators. That is problematic because there are several usage sites. Then @zepumph wrote: Michael Kauzmann [11:16 AM] Sam Reid [11:19 AM] |
using
|
Also, please search through the repos for |
I removed one todo. I also am stumped about the other two. |
Everything else looks good though. |
Oh! I'm also wanting to discuss what we decided about the |
Now that IO Types are es6 classes, inheritance is supported. That said we have i still see one more TODO for this issue: // x === phet.phetio.phetioCommandProcessor not exist yet, see https://github.com/phetsims/axon/issues/226
// TODO: Can this be eliminated? see https://github.com/phetsims/phet-io/issues/1371
PhetioCommandProcessorIO.validator = { isValidValue: x => true };
PhetioCommandProcessorIO.typeName = 'PhetioCommandProcessorIO';
ObjectIO.validateSubtype( PhetioCommandProcessorIO ); |
Looks like no more TODOs now that we have IOTypes declared in the core types. Closing. |
From #204. Now that we have an improved pattern for validation for IO type values, we should leverage that instead of having a parallel but different way of validating via
assertInstanceOf
.The text was updated successfully, but these errors were encountered: