phetsims / utterance-queue

Alerting library powered by aria-live
MIT License
0 stars 2 forks source link

Utterance.canAnnounceProperty should interrupt the Announcer when it becomes false #77

Closed jessegreenberg closed 2 years ago

jessegreenberg commented 2 years ago

An extension and enhancement of phetsims/scenery/issues/1300, when the Utterance.canSpeakProperty becomes false it should interrupt the Announcer if it is currently being announced.

jessegreenberg commented 2 years ago

This was simple enough, the change is working nicely. Tested with Dialogs and ReadingBlocks which now interrupt when closed.

jessegreenberg commented 2 years ago

This is to be reviewed as part of the set from https://github.com/phetsims/scenery/issues/1300 by @zepumph, reopening. And thank you!

zepumph commented 2 years ago

This looks really nice, thanks! Instead of creating a new closure each time we speak, can you attach a bound prototype method, or even a member variable that is set once, and then have a second value like this.canAnnouncePropertyLinked:boolean that you check instead of checking if the listener itself is null? I think that would be slightly cleaner. If you disagree that is fine too. Feel free to close.

jessegreenberg commented 2 years ago

Great idea thanks. I went with a bound method. While I was testing this I realized that after #82 we need to do this for both utterance.canAnnounceProperty and utterance.voicingCanAnnounceProperty so I did that as well in the above commit. I verified that it was still working and sims passed fuzzing.

@zepumph can you take a look at this again?

zepumph commented 2 years ago

Looks great, thanks!