Skip to content

Commit

Permalink
add comparison of description alerts, and fix compareDescription quer…
Browse files Browse the repository at this point in the history
…y parameter, phetsims/aqua#127
  • Loading branch information
zepumph committed Aug 3, 2021
1 parent 19e8b26 commit 68402d0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
28 changes: 23 additions & 5 deletions js/Utterance.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ class Utterance {
}

/**
* Getter for the text to be alerted for this Utterance. This should only be called when the alert is about to occur
* because Utterance updates the number of times it has alerted based on this function, see this.numberOfTimesAlerted
* Get the string to alert, with no side effects
* @private
* @returns {string}
* @public (UtteranceQueue only)
*/
getTextToAlert() {
getAlertText() {
let alert;
if ( typeof this._alert === 'string' ) {
alert = this._alert;
Expand All @@ -130,7 +129,18 @@ class Utterance {
const currentAlertIndex = Math.min( this.numberOfTimesAlerted, this._alert.length - 1 );
alert = this._alert[ currentAlertIndex ];
}
this.numberOfTimesAlerted++;
return alert;
}

/**
* Getter for the text to be alerted for this Utterance. This should only be called when the alert is about to occur
* because Utterance updates the number of times it has alerted based on this function, see this.numberOfTimesAlerted
* @returns {string}
* @public (UtteranceQueue only)
*/
getTextToAlert() {
const alert = this.getAlertText();
this.numberOfTimesAlerted++; // TODO: this should be called incremented by utteranceQueue directly, so that this could just be a normal getter function, see https://github.com/phetsims/utterance-queue/issues/2
return alert;
}

Expand Down Expand Up @@ -176,6 +186,14 @@ class Utterance {
this.stableTime = 0;
}

/**
* @public
* @returns {string}
*/
toString() {
return `Utterance#${this.getAlertText()}`;
}

/**
* @public
*/
Expand Down
8 changes: 8 additions & 0 deletions js/UtteranceQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ class UtteranceQueue extends PhetioObject {
}
}

/**
* @public
* @returns {number}
*/
get length() {
return this.queue.length;
}

/**
* Get the HTMLElement that houses all aria-live elements needed for the utterance queue to alert.
* @public
Expand Down

0 comments on commit 68402d0

Please sign in to comment.