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

Convert Voicing.js and others (6 mixins) to new mixin pattern and typescript #1340

Closed
zepumph opened this issue Jan 24, 2022 · 51 comments
Closed

Comments

@zepumph
Copy link
Member

zepumph commented Jan 24, 2022

This will be helpful for phetsims/ratio-and-proportion#404, and is aligned with quarterly goals.

Note: phetsims/tasks#1096

@zepumph zepumph self-assigned this Jan 24, 2022
@zepumph
Copy link
Member Author

zepumph commented Jan 24, 2022

Tagging @jessegreenberg

@zepumph
Copy link
Member Author

zepumph commented Jan 25, 2022

I found that I had to make a couple of things public from private/protected in Voicing because of TS4094 (explained in microsoft/TypeScript#30355 (comment)). I marked a couple of TODOs pointing to the change.

I tried to convert Voicing to typescript so that I could specify that it can only provide Node subtypes to be extended, and I ran into that same issue. Since there are protected/private members on Node, it seems like we are a bit stuck. I am pretty sure that I have to give up here. At least for now.

voicingTypescriptPatch.txt (first you need to rename Voicing.js -> Voicing.ts)

I also wanted to tag @samreid because I was talking to him on slack and he mentioned https://www.typescriptlang.org/docs/handbook/mixins.html#constrained-mixins. I believe that this is how we ran into the issue above where we can't have private members.

@samreid
Copy link
Member

samreid commented Jan 25, 2022

@jonathanolson is the expert on TypeScript mixins and the constraints around private/public members and may be able to recommend how to proceed here.

Also, I skimmed the patch and am wondering if it would work for this case to do class VoicingNode extends Node instead?

@zepumph
Copy link
Member Author

zepumph commented Jan 25, 2022

I do not think so, the current structure is as such for 6+ mixins:

InteractiveHighlighting
  Voicing
    ReadingBlock
    AccessibleValueHander
      AccessibleSlider
      AccessibleNumberSpinner

That said, it is a recent addition from AccessibleValueHandler to extend Voicing, and if we had to, we could likely move away from it (it's sorta up in the air anyways).

Many usages of Voicing and AccessibleValueHandler are added into the middle of hierarchies, and with typescript I wouldn't know how to say Voicing extends Node, but could somehow be tacked into a hierarch under Path/Rectangle etc.

To see usages of this, I searched for extends [^N](.*\n.*)*initializeVoicing, and found that Voicing is mixed into Node, Rectangle, Path, Vbox, RichTextLeaf and many others in the future.

I reached out to @jonathanolson to see if we could move forward with this pattern.

@zepumph
Copy link
Member Author

zepumph commented Jan 25, 2022

In a conversation with @jonathanolson this afternoon, he pointed me towards the pattern used in Paintable, as well as the general issue phetsims/chipper#1127.

zepumph added a commit to phetsims/utterance-queue that referenced this issue Jan 26, 2022
zepumph added a commit to phetsims/utterance-queue that referenced this issue Jan 26, 2022
zepumph added a commit to phetsims/inverse-square-law-common that referenced this issue Jan 26, 2022
zepumph added a commit to phetsims/gravity-force-lab-basics that referenced this issue Jan 26, 2022
zepumph added a commit to phetsims/ratio-and-proportion that referenced this issue Jan 26, 2022
zepumph added a commit to phetsims/john-travoltage that referenced this issue Jan 26, 2022
zepumph added a commit to phetsims/utterance-queue that referenced this issue Jan 26, 2022
zepumph added a commit to phetsims/quadrilateral that referenced this issue Jan 26, 2022
zepumph added a commit to phetsims/scenery-phet that referenced this issue Jan 26, 2022
zepumph added a commit that referenced this issue Jan 26, 2022
@zepumph
Copy link
Member Author

zepumph commented Jan 26, 2022

So far so good. I'm going to proceed with some of the TODOs in the issue. (currently 21)

zepumph added a commit to phetsims/sun that referenced this issue Feb 8, 2022
zepumph added a commit to phetsims/phet-info that referenced this issue Feb 8, 2022
@zepumph
Copy link
Member Author

zepumph commented Feb 8, 2022

Lots of TODOs were removed in #1351.

@zepumph
Copy link
Member Author

zepumph commented Feb 8, 2022

There are only two more open questions for me in this issue. 4 TODOs (2 topics repeated in two spots each):

  • @jonathanolson, can you figure out why this is causing a lint error?

// TODO: Why is this causing a lint error? AlertableDef is in phet-types. https://github.com/phetsims/scenery/issues/1340

  • This is for typescript in general in scenery. I'm wondering how scenery listeners can support more specific subtypes of the window.Event interface. For example, I need access to items that only some events have, like KeyboardEvent. Can you recommend how to proceed here?

https://github.com/phetsims/sun/blob/a18ba9c51046f8885d96b3baa1d4ae037fe8c161/js/accessibility/AccessibleNumberSpinner.ts#L112

@zepumph zepumph removed their assignment Feb 8, 2022
@jonathanolson
Copy link
Contributor

can you figure out why this is causing a lint error?

Not immediately sure. I don't think that eslint checks the phet-types file, presumably we'd want that type somewhere it's imported.

This is for typescript in general in scenery. I'm wondering how scenery listeners can support more specific subtypes of the window.Event interface. For example, I need access to items that only some events have, like KeyboardEvent. Can you recommend how to proceed here?

Presumably SceneryEvent would support a type parameter, and we could have subtypes so that it's more type-safe.

zepumph added a commit that referenced this issue Feb 8, 2022
zepumph added a commit to phetsims/sun that referenced this issue Feb 8, 2022
zepumph added a commit to phetsims/utterance-queue that referenced this issue Feb 8, 2022
zepumph added a commit to phetsims/scenery-phet that referenced this issue Feb 8, 2022
zepumph added a commit to phetsims/chipper that referenced this issue Feb 8, 2022
zepumph added a commit to phetsims/sun that referenced this issue Feb 8, 2022
@zepumph
Copy link
Member Author

zepumph commented Feb 8, 2022

I liked typecasting as a KeyboardEvent much more, enough to remove the TODO. Even if this sticks around for a while, it feels pretty low stakes, and safe. I also converted AlertableDef to typescript, just to add the type (TAlertableDef), which is fine for now. We can't rename it until all usages of AlertableDef.isAlertableDef are in typescript files (unless we delete them). I'm ready to close this issue. Anything else here @jonathanolson?

@zepumph zepumph assigned jonathanolson and unassigned zepumph Feb 8, 2022
@jonathanolson
Copy link
Contributor

Looks good to close, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants