PhetioIDUtils

PhetioIDUtils

Helpful methods for manipulating phetioIDs. Used to minimize the amount of duplicated logic specific to the string structure of the phetioID. Available in the main PhET-iO js import.

Members

(static, constant) GENERAL_COMPONENT_NAME :String

The component name for the id section that holds phet-io elements general to all simulations.
Type:
  • String

(static, constant) GLOBAL_COMPONENT_NAME :String

The component name for the id section that holds simulation specific elements that don't belong in a screen.
Type:
  • String

(static, constant) GROUP_SEPARATOR :String

The separator used to specify the count of a element in a group.
Type:
  • String

(static, constant) HOME_SCREEN_COMPONENT_NAME :String

The component name for the id section that holds the home screen.
Type:
  • String

(static, constant) MODEL_COMPONENT_NAME :String

The component name for an id section that holds model specific elements.
Type:
  • String

(static, constant) SEPARATOR :String

The separator used to piece together a phet-io ID.
Type:
  • String

(static, constant) VIEW_COMPONENT_NAME :String

The component name for an id section that holds view specific elements.
Type:
  • String

Methods

(static) append(phetioID, componentNames) → {string}

Appends a component to an existing phetioID to create a new unique phetioID for the component.
Example
append( 'myScreen.myControlPanel', 'myComboBox' )
-->  'myScreen.myControlPanel.myComboBox'
Parameters:
Name Type Description
phetioID string the ID of the PhET-iO element
componentNames string | Array.<string> the name or list of names to append to the ID
Returns:
- the appended phetioID
Type
string

(static) getComponentName(phetioID) → {string}

Given a phetioID for a PhET-iO element, get the part of that ID that pertains to the component (basically the tail piece).
Example
getComponentName( 'myScreen.myControlPanel.myComboBox' )
-->  'myComboBox'
Parameters:
Name Type Description
phetioID string the ID of the PhET-iO element
Returns:
- the component name
Type
string

(static) getDOMElementID(phetioID) → {string}

Given a phetioID for a instrumented object, get a string that can be used to assign an ID to a DOM element
Parameters:
Name Type Description
phetioID string the ID of the PhET-iO element
Returns:
Type
string

(static) getGeneralID(Client, componentNames) → {string}

The root sim ID has a nested "general" ID which contains several simulation-level components. This method can be used for convenience in accessing its child elements.
Example
getGeneralID( phetio.Client, 'activeProperty' );
-->  'faradaysLaw.general.activeProperty'

getGeneralID( phetio.Client, [ 'mySubComponent', 'activeProperty' ] );
-->  'faradaysLaw.general.mySubComponent.activeProperty'
Parameters:
Name Type Description
Client Client the Client type, not a Client instance
componentNames string | Array.<string> to append to the general ID stub
Returns:
Type
string

(static) getGroupElementIndex(componentName) → {number}

Get the index number from the component name of the component name provided.
Example
getGroupElementIndex( 'particle_1' )
--> 1
Parameters:
Name Type Description
componentName string
Returns:
Type
number

(static) getParentID(phetioID) → {string|null}

Given a phetioID for a PhET-iO element, get the phetioID of the parent component.
Example
getParentID( 'myScreen.myControlPanel.myComboBox' )
-->  'myScreen.myControlPanel'
Parameters:
Name Type Description
phetioID string the ID of the PhET-iO element
Returns:
- the phetioID of the parent, or null if there is no parent
Type
string | null

(static) getScreenID(phetioID) → {string|null}

Get the screen id from the phetioID.
Example
getScreenID( 'sim.myScreen.model.property' )
--> sim.myScreen
getScreenID( 'sim.myScreen' )
--> sim.myScreen
getScreenID( 'sim.general.activeProperty' )
--> null
Parameters:
Name Type Description
phetioID string
Returns:
- null if there is no screen component name in the phetioID
Type
string | null

(static) isAncestor(potentialAncestorPhetioID, potentialDescendantPhetioID) → {boolean}

Returns true if the potential ancestor is indeed an ancestor of the potential descendant, but not the same phetioID
Parameters:
Name Type Description
potentialAncestorPhetioID string
potentialDescendantPhetioID string
Returns:
Type
boolean