Skip to content

Commit

Permalink
simplify the setting of isResettingAllProperty, see phetsims/tambo#190
Browse files Browse the repository at this point in the history
(cherry picked from commit fb06b0d)
  • Loading branch information
jbphet authored and matthew-blackman committed Apr 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 305e839 commit 68f0c63
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions js/buttons/ResetAllButton.ts
Original file line number Diff line number Diff line change
@@ -38,16 +38,6 @@ export default class ResetAllButton extends ResetButton {

public constructor( providedOptions?: ResetAllButtonOptions ) {

// Wrap the provided listener in a new function that sets and clears the isResettingAllProperty flag.
if ( providedOptions && providedOptions.listener ) {
const originalListener = providedOptions.listener;
providedOptions.listener = () => {
isResettingAllProperty.value = true;
originalListener();
isResettingAllProperty.value = false;
};
}

const options = optionize<ResetAllButtonOptions, SelfOptions, ResetButtonOptions>()( {

// ResetAllButtonOptions
@@ -139,9 +129,16 @@ export default class ResetAllButton extends ResetButton {
} );
this.addInputListener( keyboardListener );

// Add a listener that will set and clear the static flag that signals when a reset all is in progress.
const flagSettingListener = ( isFiring : boolean ) => {
isResettingAllProperty.value = isFiring;
};
this.pushButtonModel.isFiringProperty.lazyLink( flagSettingListener );

this.disposeResetAllButton = () => {
this.removeInputListener( keyboardListener );
ariaEnabledOnFirePerUtteranceQueueMap.clear();
this.pushButtonModel.isFiringProperty.unlink( flagSettingListener );
};
}

@@ -150,6 +147,8 @@ export default class ResetAllButton extends ResetButton {
super.dispose();
}

// A flag that is true whenever any "reset all" is in progress. This is often useful for muting sounds that shouldn't
// be triggered by model value changes that occur due to a reset.
public static isResettingAllProperty: TReadOnlyProperty<boolean> = isResettingAllProperty;
}

0 comments on commit 68f0c63

Please sign in to comment.