Closed zepumph closed 1 year ago
In light of https://github.com/phetsims/chipper/issues/1283, perhaps a type
should be used instead of interface
.
Working progress:
@marlitas and I added IEmitter
in the commit and converted declarations of TinyEmitter
to IEmitter
. But despite yesterday's conversation about choosing the appropriate return/declare type, we thought in some cases it might be appropriate to look at declarations so the developer can instantly see it is the "low memory" variant even though details from that interface are not used. Anyways, we weren't sure about that but wanted to keep going.
This has been implemented and seems to be working well. Some notes:
isDisposed
out of the interface since it differs dramatically between Emitter and TinyEmitter. TinyEmitter only allocates space for that when assertions are enabled.Outstanding topics for discussion:
Otherwise, this issue is ready for review.
We left isDisposed out of the interface since it differs dramatically between Emitter and TinyEmitter. TinyEmitter only allocates space for that when assertions are enabled.
Yes. That is totally right in my opinion.
Should it be called IEmitter?
https://github.com/phetsims/chipper/issues/1287 is no longer blocking. We want to name the interface Emitter
and name Emitter.ts to something else. What should that be?
Should we sometimes prefer TinyEmitter to IEmitter declarations in scenery so it is obvious that it is using the low-memory variant? Even though we don’t use details from that interface.
We discussed this at a dev meeting. The public declaration should be an IEmitter if that is all users of the type need to know. The implementation can still be TinyEmitter.
@marlitas and I reviewed TinyEmitter
, IEmitter
, Emitter
and several usage sites and we recommend the following steps:
new PhetioEmitter
and see if any of them should be changed to new TinyEmitter
. : Emitter
instead of : PhetioEmitter
or : TinyEmitter
.Due to the immense amount of work proposed, we would like to confirm with the dev team before starting.
We discussed this at developer meeting today.
In general, we feel like the Phetio
prefix for these central types is not the best choice. While that prefix means something to us, it isn't quite as valuable to describe these types to others (perhaps new members of the project).
We don't feel like this rename would be worth the cost. "bang for the buck" was said about 12 times during our conversation.
We recommend renaming IEmitter -> TEmitter and to be done with this issue.
Likewise, rename Property to PhetioProperty, probably in a side issue since it will be a lot of work.
We feel the same way about the "Phetio" part here. It was also mentioned that we should absolutely not do this until first tackling the larger issue of https://github.com/phetsims/axon/issues/404
- Visit usage sites that instantiate
new PhetioEmitter
and see if any of them should be changed tonew TinyEmitter
.
TinyEmitter is not our central emitter, but is only for when we run into performance problems. We as the developers at the 8/4 meeting do not recommend doing this work.
- See if any declarations should be
: Emitter
instead of: PhetioEmitter
or: TinyEmitter
.
Every declaration possible should be TEmitter instead of either class (implementation detail).
I renamed IEmitter to TEmitter. I checked for type annotations that should be changed and only saw one.
I think this issue is ready to close. @marlitas can you please spot check? Close if all is well.
Did a quick spot check, and all looks good. Will add IEmitterListener & IEmitterParameter to our list in: https://github.com/phetsims/chipper/issues/1287 Closing.
@samreid and I discussed this today, and thought it was a bit weird to not have Emitter and TinyEmitter implementing an interface. This will at the very least keep their APIs in sync (they are almost identical currently but not quite, and we should work that out).
This is also helpful for the cases where Emitters are dependency injected, for example:
https://github.com/phetsims/phet-io/blob/917a4a49656af32eac764b715e84de3859f27717/js/phetioEngine.ts#L269
PhetioEngine does not need to know about the guts of Emitter, it should use IEmitter, just like how we use IReadOnlyProperty.
We also thought that in general we should use IEmitter as typescript
We want to use an explicit IEmitter instead of using TinyEmitter's type dynamically in Emitter, not like this: