phetsims / utterance-queue

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

Create an enumeration for Utterance priorities #78

Closed jessegreenberg closed 1 year ago

jessegreenberg commented 2 years ago

Currently Priorities can take any number value, it would be better if there were some limit on the values you could provide. It seems like allowing any number could turn into mayhem.

We think an enumeration for these values would be nice. We also considered typing Priority, but we want to start with enumeration.

zepumph commented 2 years ago

see https://github.com/phetsims/joist/issues/752#issuecomment-1098457878

zepumph commented 2 years ago

Something like:


class Priority extends EnumerationValue {
  // Priority levels that can be used by Utterances providing the `announcerOptions.priority` option.
  public static TOP_PRIORITY = new Priority( 10 );
  public static HIGH_PRIORITY = new Priority( 5 );
  public static MEDIUM_PRIORITY = new Priority( 2 );
  public static DEFAULT_PRIORITY = new Priority( DEFAULT_PRIORITY );
  public static LOW_PRIORITY = new Priority( 0 );

  public constructor( public readonly priorityNumber: number ) {super();}

  public static enumeration = new Enumeration( Priority );
}
zepumph commented 1 year ago

I kinda like just having a number. It makes things a bit more flexible and so far we haven't run into trouble. Closing, but please reopen if you disagree.