Skip to content

Commit

Permalink
Factor out screen tandem name suffix, see #267
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Aug 15, 2022
1 parent 90a2c6a commit cab8392
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions js/PhetioIDUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
const VIEW_COMPONENT_NAME = 'view';
const COLORS_COMPONENT_NAME = 'colors';
const CONTROLLER_COMPONENT_NAME = 'controller';
const SCREEN_COMPONENT_NAME = 'Screen';

/**
* Helpful methods for manipulating phetioIDs. Used to minimize the amount of duplicated logic specific to the string
Expand Down Expand Up @@ -120,9 +121,8 @@
for ( let i = 0; i < phetioIDParts.length; i++ ) {
const componentPart = phetioIDParts[ i ];
screenIDParts.push( componentPart );
const screenMarker = 'Screen';
const indexOfScreenMarker = componentPart.indexOf( screenMarker );
if ( indexOfScreenMarker > 0 && indexOfScreenMarker + screenMarker.length === componentPart.length ) { // endsWith proxy
const indexOfScreenMarker = componentPart.indexOf( SCREEN_COMPONENT_NAME );
if ( indexOfScreenMarker > 0 && indexOfScreenMarker + SCREEN_COMPONENT_NAME.length === componentPart.length ) { // endsWith proxy
return screenIDParts.join( SEPARATOR );
}
}
Expand Down
4 changes: 3 additions & 1 deletion js/Tandem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class Tandem {
public static OPT_OUT: Tandem;
public static REQUIRED: Tandem;

public static readonly SCREEN_TANDEM_NAME_SUFFIX = 'Screen';

/**
* Typically, sims will create tandems using `tandem.createTandem`. This constructor is used internally or when
* a tandem must be created from scratch.
Expand Down Expand Up @@ -421,7 +423,7 @@ class RootTandem extends Tandem {
name === OPTIONAL_TANDEM_NAME ||
name === TEST_TANDEM_NAME ||
name === window.phetio.PhetioIDUtils.GENERAL_COMPONENT_NAME ||
_.endsWith( name, 'Screen' );
_.endsWith( name, Tandem.SCREEN_TANDEM_NAME_SUFFIX );
assert && assert( allowedOnRoot, `tandem name not allowed on root: "${name}"; perhaps try putting it under general or global` );
}

Expand Down

0 comments on commit cab8392

Please sign in to comment.