-
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
consolidate EmitterIO args and validators to prevent duplicate arrays in options #204
Comments
I wonder if it is preferable to bundle things in the EmitterIO array? this._pressedEmitter = new Emitter( {
. . .
phetioType: EmitterIO( [
{ name: 'event', type: EventIO, valueType: Event },
{ name: 'targetNode', type: VoidIO, isValidValue: function( v ) { return v === null || v instanceof Node; } },
{ name: 'callback', type: VoidIO, isValidValue: function( v ) { return v === null || typeof v === 'function'; } }
] ),
. . .
} ); @zepumph if that sounds good to you, let me know and I'll move forward implementing it. |
That feels less good to me. I really dislike that in order create an Emitter you have to create an EmitterIO. We looked into that in #182 early on, and even implemented, but it just seems cleaner to me if move EmitterIO related stuff into We can talk more in person if you'd like. |
Uninstrumented code would use |
In discussion today, @zepumph agreed the proposal in #204 (comment) sounds reasonable and warrants investigation. |
We also discussed that if the phetioType already has IO type, then |
For instance, in DOMEventIO, we would eliminate isInstance: function( instance ) { return instance instanceof window.Event; }, and move toward a Validator-centric solution like: validatorOptions: {valueType: window.Event}, |
Marking high priority, since this is currently a gap that only get harder to fill as time goes on. |
Steps for this issue:
|
After today's discussion, will we use |
I wrote on slack:
|
This function ArithmeticModel( tandem, options ) {
var self = this;
// @private - for PhET-iO
this.checkAnswerEmitter = new Emitter( {
tandem: tandem.createTandem( 'checkAnswerEmitter' ),
phetioType: EmitterIO( [ { name: 'results', type: ObjectIO, validator: { validValue: Object } } ] )
} ); Because |
These changes will also allow us to replace all of the |
|
I see your point about NullableIO.validator. Maybe we need to define something like isValidValue: function( instance ) {
return instance === null || isValid( instance, ioType.validator );
} Or maybe validate should return a boolean? |
@zepumph and I reviewed the existing code and made numerous changes in the preceding commits. Tests are working, we have improved feature coverage without sacrificing good assertion messages. The strategy of passing through We marked one TODO regarding garbage. |
@zepumph and I finished reviewing and committing, and decided this issue is complete. |
From #182 (comment)
We now are using
Validator
to validate Emitter args. The next step is to get rid of the duplicated arrays inargumentTypes:[*]
and phetioType: EmitterIO([ * ])`.To search for current places where this is a problem, search for the TODO:
// TODO: use of both of these is redundant, and should get fixed with https://github.com/phetsims/axon/issues/194
I think it should be solved in this issue instead, where it is specific to EmitterIO.
On top of just supporting the
type
value in objects passed to EmitterIO, I think we should streamline all of the keys. So we would movename
anddocumentation
intoargumentTypes
also (perhapsargumentTypes
should be renamed?For example, take this current implementation in PressListener:
could become something like:
Then in Emitter, we could create the actual instance of EmitterIO that is needed.
In some cases, we may be able to get away with gathering the valueType from the phetioType, for example
EventIO
can have a pointer to its "core type" which isEvent
, so we don't need both of those. One downside of this is that we now can't factor out EmitterIO types. @samreid how might we get around that? Can you think of anything else that I'm missing from our conversation last week? I remember specifically talking about how we will have EITHER phetioType OR valueType, but theVoidIO
example complicates that I think.The text was updated successfully, but these errors were encountered: