-
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
Should each Emitter instance be allowed to emit with any number of args? #182
Comments
Adding to developer meeting, although likely it would be nice to have a week of async discussion and thought gathering before bringing this to the team. |
I appreciate the simplicity of a single |
Another possibility would be to convert everything to be |
For PhET-iO would we then need a |
Also note that there are only 35 or so usages of |
Well, each EmitterIO would be created with the appropriate type on a case-by-case basis (instead of thinking of one type that works for everything). For instance: new Emitter({phetioType: EmitterIO(StringIO)});
new Emitter({phetioType: EmitterIO()}); // for no-args?
new Emitter({phetioType: EmitterIO(ArrayIO(Vector2IO))}); |
Do Emitter instances typically use one of the |
Seems like a hard question to answer definitively. I can say with relatively strong confidence that I have not emitted using multiple methods for the same emitter instance. |
Since all listeners are called when any emit method is called, I don't see how using more than 1 of the emit methods would not be buggy. And if it did work, it seems like a bad practice to use an Emitter for more than one purpose. |
Springboarding from that, perhaps the easiest solution to validate is to have an option of type EDIT: this option may have a default of 0, but could be easily overridable. |
I'm now recalling the 2 things that I don't like about the current Emitter implementation. What @zepumph proposed in #182 (comment) sounds like a reasonable way to prevent you from using more than one emit method. |
If the concern is serialization, couldn't emitters be given an array of phet-io types for the arguments? |
Yes that is what we currently do (see |
For the record, I've never had a case where I used different numbers of params from the same emitter. |
Decided in the developer meeting, we will update Then in the This code will mimic that of For PhET-iO we will have a parallel array option I'll give this one a go. |
(phet-io thanks you) |
I think this is safest to try to accomplish in steps, rather than just one super commit. I think I will do the following steps:
|
|
Can they come from the Property's validValues? Or maybe we don't need to supply them because the Property.changeEmitter is not instrumented? |
Converting usages of |
Thoughts while working on this:
Summary of work:
Overall I'm happy about this change, and I think, after a review, phet brand should be cleared to use this approach for creating emitters. The main drag about the above commit is that it doesn't yet support phetioType as part of argumentTypes, which I think is the way to go so we don't have to support parallel arrays. But since we don't support that yet, for phet-io instrumented Emitters we have an array for I pointed to that issue instead of this one because that is above consolidating phetioType and the traditional "valueType" into a single place. @samreid and I still need to support moving EmitterIO types into argumentTypes for Emitter specifically. I'll make a new issue for that. |
I don't want un-reviewed code in master for too long. marking blocks publication. |
@chrisklus @zepumph and I reviewed the preceding commits and comments. We have a few recommendations to commit, and will open two follow-up issues. |
Review is complete, this is working nicely and follow-up work is lower priority and noted in other issues. |
Right now there is complete flexibility on how many arguments you emit with for an emitter instance. So far there haven't seen to be any complaints about this loose system, but @samreid, @chrisklus, and @zepumph ran into difficulties with this for PhET-iO today.
Would this be safer and more maintainable if an Emitter instance was defined with a set number of args that it expected to emit with? Perhaps this would be too rigid of a system? Are there many places where a single emitter will use more than one emitting function in different use cases?
For example, here is something you can currently do with Emitter:
For obvious reasons, this seems brittle and difficult when it comes to adding listeners to this
Emitter
.The reason this came up, was because we were trying to decide how
EmitterIO
should properly serialize Emitter's arg types. For example we have anEmitterIO.<BooleanIO>
that is still technically allowed toemit3()
, although that breaks across the phet-io api.A "strong typing" solution (that we aren't necessarily pushing for) would be to have a different type for each number of args you plan to emit for, like
Emitter extends BaseEmitter
,Emitter1 extends BaseEmitter
,Emitter2 extends BaseEmitter
. Each type would only have the emitting method that corresponds to the number of args it is made for.The text was updated successfully, but these errors were encountered: