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

Should validate be moved out of axon? #361

Closed
jessegreenberg opened this issue Sep 27, 2021 · 12 comments
Closed

Should validate be moved out of axon? #361

jessegreenberg opened this issue Sep 27, 2021 · 12 comments
Assignees

Comments

@jessegreenberg
Copy link
Contributor

In phetsims/utterance-queue#33 I tried to use validate in a new function in phet-core. But phet-core shouldn't have a dependency on axon because axon already depends on phet-core.

I am wondering if validate and ValidatorDef should be moved to phet-core (or maybe somewhere else) as its usage does not seem limited to observables and axon things.

Assigning to @samreid and @zepumph for thoughts.

@jessegreenberg jessegreenberg changed the title Should validate live in axon? Should validate be moved out of axon? Sep 27, 2021
@zepumph
Copy link
Member

zepumph commented Sep 27, 2021

Yes, this should move to phet-core, but I really want to keep the history. Can we please use copy-history-to-different-repo.sh to move over validate.js, ValidatorDef.js, and ValidatorDefTests.js?

@zepumph zepumph assigned jessegreenberg and unassigned zepumph Sep 27, 2021
@samreid
Copy link
Member

samreid commented Sep 27, 2021

ValidatorDefTests imports from both scenery/ and tandem/. Do we really want to put a dependency from phet-core to scenery and tandem? How else can this be done? Should we drop the Node parts of the tests, and use EnumerationIO instead of StringIO in the tests?

@jessegreenberg
Copy link
Contributor Author

jessegreenberg commented Sep 27, 2021

Are those tests in ValidatorDefTests specific to ValidatorDef or could they be moved to other tests? For example could the 'Test phetioType' portion be moved to IOTypeTests.js or something else?

@zepumph
Copy link
Member

zepumph commented Sep 27, 2021

A couple of things here.

  • EnumerationIO is in phet-core and uses tandem.
  • All the cross dependencies are arbitrary, and just there to test types. They could easily be rewritten to just use IOTypes in phet-core.
  • In general, I thought that tests don't have the same constraints on dependencies than other code. Is that not true? If that has changed for typescript, or if I never understood to begin with, then do we need to discuss this at dev meeting?
  • Let me know if you want me to do that refactor for test dependencies.

@zepumph zepumph removed their assignment Sep 27, 2021
@samreid
Copy link
Member

samreid commented Sep 28, 2021

EnumerationIO is in phet-core and uses tandem.

Yes, this creates complications for TypeScript. Note that EnumerationIO is excluded from phet-core/tsconfig.json, and included over in tandem/tsconfig.json.

All the cross dependencies are arbitrary, and just there to test types. They could easily be rewritten to just use IOTypes in phet-core.

That seems like a good move.

In general, I thought that tests don't have the same constraints on dependencies than other code. Is that not true? If that has changed for typescript, or if I never understood to begin with, then do we need to discuss this at dev meeting?

I started to observe these problems in phetsims/chipper#1052 and made progress on phetsims/chipper#1055. To me, it adds complexity that, say, phet-core imports files from scenery. I'm not aware of any prior problems with that, but it has created wrinkles for TypeScript.

Let me know if you want me to do that refactor for test dependencies.

That would be great, thanks! I can also volunteer, but am very backlogged at the moment.

@zepumph
Copy link
Member

zepumph commented Sep 30, 2021

I will try hard to get to the grunt work here soon to get this off hold for phetsims/utterance-queue#33

@zepumph
Copy link
Member

zepumph commented Sep 30, 2021

Yes, this creates complications for TypeScript. Note that EnumerationIO is excluded from phet-core/tsconfig.json, and included over in tandem/tsconfig.json.

@samreid, would you like me to make an issue to move IO types in phet-core out to tandem? Perhaps a lint rule in phet-core to make sure that it doesn't have any cross dependencies?

@samreid
Copy link
Member

samreid commented Sep 30, 2021

Is EnumerationIO the only IO type in phet-core? Would we want to move it out but leave Enumeration, EnumerationMap and EnumerationTests behind? What is the likelihood Enumeration will one day need to import EnumerationIO?

@zepumph
Copy link
Member

zepumph commented Sep 30, 2021

What is the likelihood Enumeration will one day need to import EnumerationIO?

Very high in my opinion. Most likely it should be in there now. Similar to the way we do other data types like Vector2IO.


ValidatorDef as a feature does depend on tandem though, even if the tests don't reflect that. This is because a validator can have a phetioType provided. This is of type IOType, even if we don't include that check in code that lives in phet-core. I think I would rather have a cross dependency, than for that to be behind the scenes.

Currently it is just duck typed:

axon/js/ValidatorDef.js

Lines 158 to 164 in 201a8de

if ( validator.hasOwnProperty( 'phetioType' ) ) {
if ( !( validator.phetioType && validator.phetioType.validator ) ) {
assert && options.assertions && assert( false, `validator needed for phetioType: ${validator.phetioType && validator.phetioType.typeName}` );
return false;
}
return ValidatorDef.isValidValidator( validator.phetioType.validator, options );
}

But I don't think that is as good as if there was an instanceof check for IOType.

I don't see these relationships as hierarchical, so I don't really know how to proceed. We could create some sort of central library of phet that DOES depend on tandem, and keep phet-core as something like has no dependencies. Then Enumeration would also go into the other library.

@zepumph zepumph removed their assignment Sep 30, 2021
@zepumph
Copy link
Member

zepumph commented Oct 1, 2021

This needs to be solved for Enumeration and tandem at the same time. BTW we are no longer blocking phetsims/utterance-queue#33, as we found a way around it.

@samreid
Copy link
Member

samreid commented Oct 2, 2021

After our discussion today, it's unclear to me what the options are, or what else we need to discuss/decide before we can proceed. @zepumph can you please advise?

@zepumph
Copy link
Member

zepumph commented Oct 8, 2021

This does not need to need to occur for any issue that this was originally brought up for. While it doesn't totally make sense for this to be in axon, we don't currently have a better spot for it that doesn't create another headache for cross dependencies. Let's reopen if we find this to dependency tree to be too burdensome. Closing

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

3 participants