Closed zepumph closed 2 years ago
Should be complete by the end of next week for Number Play.
We also want to make the pattern clear in EnumerationProperty, about passing in the appropriate validValues (which could be a subset of the available Enumeration. I'll potentially make a new issue to support that.
That was done in https://github.com/phetsims/axon/issues/374
@chrisklus you should be all good here. I also wrote unit tests to ensure some behavior. Please note that when subtyping, you really cannot trust or use EnumerationValue.enumeration. As a result, I would recommend coding around that, probably just using MySubtypeEnumeration.enumeration always (as a static), and not value => value.enumeration
.
Please review, and we can pick up the conversation over in https://github.com/phetsims/phet-core/issues/101.
Thanks @zepumph! Everything done in this issue looks great. I am still running into an issue when using my enum subtype with EnumerationProperty. I think it is related to the additional validation done with the phetioType, since that is still using value.enumeration
:
const options = merge( {
validValues: value.enumeration!.values,
phetioType: Property.PropertyIO( EnumerationIO<T>( {
enumeration: value.enumeration!
} ) )
}, providedOptions );
Maybe enumeration
could be an option to EnumerationProperty?
Here is a patch to reproduce:
I did not apply your patch, but I added some unit tests. Is this what you were thinking?!
Sorry for the delay - that's exactly what i was thinking, thanks! I too was trying to craft up something like firstOptions
when trying this out. Commits look great and using this in practice is working really well.
I'm ready to close, and will update #101.
Tagging https://github.com/phetsims/chipper/issues/1106. Over in https://github.com/phetsims/phet-core/issues/101, @chrisklus reported a strange bug that has to do with mutating EnumerationValue instances depending on what Enumeration they are part of. We recommend a couple of changes to the pattern.
Basically we need to make sure that MyEnumeration.SOME_VALUE.enumeration is always of type MyEnumeration, even if MyEnumeration is a subtype or supertype of other EnumerationValues. This means guarding this line https://github.com/phetsims/phet-core/blob/c2d477a21fcc5259360d0fc820f5e6fab9b708da/js/Enumeration.ts#L74.
We also want to make the pattern clear in EnumerationProperty, about passing in the appropriate validValues (which could be a subset of the available Enumeration. I'll potentially make a new issue to support that.