phetsims / tandem

Simulation-side code for PhET-iO
MIT License
0 stars 5 forks source link

Move ObjectIO to PhetioObject #232

Closed zepumph closed 3 years ago

zepumph commented 3 years ago

This will help with https://github.com/phetsims/phet-io/issues/1753, and also just makes sense in general. Tagging @samreid.

zepumph commented 3 years ago

I got totally stuck here with circular dependencies.

We need IOType from PhetioObject (like when we create ObjectIO), but IOType needs to know about the base supertype, which is PhetioObject.ObjectIO. I tried to use phet.tandem.PhetioObject.ObjectIO, but not all IOTypes are used by PhetioObjects, like FunctionIO and EnumerationIO. I thought I could get around this in a hacky way by just importing PhetioObject manually by those types, but that is a race condition in imports. I don't know how to proceed here, which means I also feel totally blocked on the conversion to metadataDefaults over in https://github.com/phetsims/phet-io/issues/1753.

Here is my patch so far, if I make any commits over in https://github.com/phetsims/phet-io/issues/1753 though it likely won't apply nicely.

```diff Index: gravity-and-orbits/js/common/GravityAndOrbitsScene.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/gravity-and-orbits/js/common/GravityAndOrbitsScene.js b/gravity-and-orbits/js/common/GravityAndOrbitsScene.js --- a/gravity-and-orbits/js/common/GravityAndOrbitsScene.js (revision 2ed8ecb07c1e16ed65092c49dbf9ce814e3e447f) +++ b/gravity-and-orbits/js/common/GravityAndOrbitsScene.js (date 1617991660512) @@ -25,7 +25,6 @@ import ModelViewTransform2 from '../../../phetcommon/js/view/ModelViewTransform2.js'; import PhetioObject from '../../../tandem/js/PhetioObject.js'; import Tandem from '../../../tandem/js/Tandem.js'; -import IOType from '../../../tandem/js/types/IOType.js'; import ReferenceIO from '../../../tandem/js/types/ReferenceIO.js'; import gravityAndOrbits from '../gravityAndOrbits.js'; import GravityAndOrbitsConstants from './GravityAndOrbitsConstants.js'; @@ -74,7 +73,7 @@ super( { phetioDocumentation: 'A group of orbital masses which can be selected', - phetioType: ReferenceIO( IOType.ObjectIO ), + phetioType: ReferenceIO( PhetioObject.ObjectIO ), tandem: tandem } ); Index: axon/js/EmitterIOTests.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/axon/js/EmitterIOTests.js b/axon/js/EmitterIOTests.js --- a/axon/js/EmitterIOTests.js (revision 2f7d65c8d5614b162208c99e681bf660d902193c) +++ b/axon/js/EmitterIOTests.js (date 1617991456665) @@ -7,7 +7,7 @@ */ import merge from '../../phet-core/js/merge.js'; -import IOType from '../../tandem/js/types/IOType.js'; +import PhetioObject from '../../tandem/js/PhetioObject.js'; import NumberIO from '../../tandem/js/types/NumberIO.js'; import Emitter from './Emitter.js'; @@ -27,7 +27,7 @@ assert.throws( () => { emitter = new Emitter( { - phetioType: IOType.ObjectIO + phetioType: PhetioObject.ObjectIO } ); }, 'cannot supply any phetioType' ); } Index: masses-and-springs/js/common/model/Body.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/masses-and-springs/js/common/model/Body.js b/masses-and-springs/js/common/model/Body.js --- a/masses-and-springs/js/common/model/Body.js (revision 6bd07900888fefb148bfc9c9b0a1d632e82fd834) +++ b/masses-and-springs/js/common/model/Body.js (date 1617991660460) @@ -7,6 +7,7 @@ * @author Matt Pennington (PhET Interactive Simulations) */ +import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import IOType from '../../../../tandem/js/types/IOType.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import massesAndSprings from '../../massesAndSprings.js'; @@ -47,7 +48,7 @@ Body.BodyIO = new IOType( 'BodyIO', { valueType: Body, documentation: 'Planet which determines the force of gravity.', - supertype: ReferenceIO( IOType.ObjectIO ) + supertype: ReferenceIO( PhetioObject.ObjectIO ) } ); export default Body; \ No newline at end of file Index: tandem/js/types/ValueIO.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tandem/js/types/ValueIO.js b/tandem/js/types/ValueIO.js --- a/tandem/js/types/ValueIO.js (revision 33796537fb0ee85d96f2a9119978ea01740cca85) +++ b/tandem/js/types/ValueIO.js (date 1617991660475) @@ -1,5 +1,6 @@ // Copyright 2020, University of Colorado Boulder +import PhetioObject from '../PhetioObject.js'; import tandemNamespace from '../tandemNamespace.js'; import IOType from './IOType.js'; @@ -9,7 +10,7 @@ */ const ValueIO = new IOType( 'ValueIO', { isValidValue: () => true, - supertype: IOType.ObjectIO, + supertype: PhetioObject.ObjectIO, toStateObject: coreObject => coreObject, fromStateObject: stateObject => stateObject } ); Index: masses-and-springs/js/common/model/Spring.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/masses-and-springs/js/common/model/Spring.js b/masses-and-springs/js/common/model/Spring.js --- a/masses-and-springs/js/common/model/Spring.js (revision 6bd07900888fefb148bfc9c9b0a1d632e82fd834) +++ b/masses-and-springs/js/common/model/Spring.js (date 1617991660502) @@ -17,6 +17,7 @@ import Range from '../../../../dot/js/Range.js'; import Vector2 from '../../../../dot/js/Vector2.js'; import Vector2Property from '../../../../dot/js/Vector2Property.js'; +import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import IOType from '../../../../tandem/js/types/IOType.js'; import NumberIO from '../../../../tandem/js/types/NumberIO.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; @@ -614,7 +615,7 @@ Spring.SpringIO = new IOType( 'SpringIO', { valueType: Spring, documentation: 'Hangs from the ceiling and applies a force to any attached BodyIO', - supertype: ReferenceIO( IOType.ObjectIO ) + supertype: ReferenceIO( PhetioObject.ObjectIO ) } ); export default Spring; \ No newline at end of file Index: scenery-phet/js/Stopwatch.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/scenery-phet/js/Stopwatch.js b/scenery-phet/js/Stopwatch.js --- a/scenery-phet/js/Stopwatch.js (revision cd52a156dcb4d74cad0d8553ef24b6d4dfec6756) +++ b/scenery-phet/js/Stopwatch.js (date 1617991660448) @@ -8,13 +8,12 @@ import BooleanProperty from '../../axon/js/BooleanProperty.js'; import NumberProperty from '../../axon/js/NumberProperty.js'; -import Vector2 from '../../dot/js/Vector2.js'; import Range from '../../dot/js/Range.js'; +import Vector2 from '../../dot/js/Vector2.js'; import Vector2Property from '../../dot/js/Vector2Property.js'; import merge from '../../phet-core/js/merge.js'; import PhetioObject from '../../tandem/js/PhetioObject.js'; import Tandem from '../../tandem/js/Tandem.js'; -import IOType from '../../tandem/js/types/IOType.js'; import ReferenceIO from '../../tandem/js/types/ReferenceIO.js'; import sceneryPhet from './sceneryPhet.js'; @@ -40,7 +39,7 @@ // phet-io tandem: Tandem.REQUIRED, - phetioType: ReferenceIO( IOType.ObjectIO ) + phetioType: ReferenceIO( PhetioObject.ObjectIO ) }, options ); super( options ); Index: charges-and-fields/js/charges-and-fields/view/ElectricPotentialLineView.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/charges-and-fields/js/charges-and-fields/view/ElectricPotentialLineView.js b/charges-and-fields/js/charges-and-fields/view/ElectricPotentialLineView.js --- a/charges-and-fields/js/charges-and-fields/view/ElectricPotentialLineView.js (revision 9b7bd8584263f606fd0029853e02e0b83ba15b80) +++ b/charges-and-fields/js/charges-and-fields/view/ElectricPotentialLineView.js (date 1617991660438) @@ -22,9 +22,8 @@ import Rectangle from '../../../../scenery/js/nodes/Rectangle.js'; import Text from '../../../../scenery/js/nodes/Text.js'; import PhetioObject from '../../../../tandem/js/PhetioObject.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; -import chargesAndFieldsStrings from '../../chargesAndFieldsStrings.js'; import chargesAndFields from '../../chargesAndFields.js'; +import chargesAndFieldsStrings from '../../chargesAndFieldsStrings.js'; import ChargesAndFieldsColorProfile from '../ChargesAndFieldsColorProfile.js'; import ChargesAndFieldsConstants from '../ChargesAndFieldsConstants.js'; @@ -46,7 +45,7 @@ super( { tandem: tandem, phetioDynamicElement: true, - phetioType: IOType.ObjectIO, + phetioType: PhetioObject.ObjectIO, phetioState: false } ); Index: tandem/js/types/IOType.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tandem/js/types/IOType.js b/tandem/js/types/IOType.js --- a/tandem/js/types/IOType.js (revision 33796537fb0ee85d96f2a9119978ea01740cca85) +++ b/tandem/js/types/IOType.js (date 1617992382165) @@ -18,9 +18,6 @@ // constants const VALIDATE_OPTIONS_FALSE = { validateValidator: false }; -// Defined at the bottom of this file -let ObjectIO = null; - /** * Estimate the core type name from a given IO Type name. * @param {string} ioTypeName @@ -48,7 +45,7 @@ constructor( ioTypeName, config ) { // For reference in the config - const supertype = config.supertype || ObjectIO; + const supertype = config.supertype || phet.tandem.PhetioObject.ObjectIO; config = merge( { @@ -58,7 +55,7 @@ /***** OPTIONAL ****/ - supertype: ObjectIO, + supertype: phet.tandem.PhetioObject.ObjectIO, // {Object.} The public methods available for this IO Type. Each method is not just a function, // but a collection of metadata about the method to be able to serialize parameters and return types and provide @@ -262,32 +259,6 @@ } } -ObjectIO = new IOType( 'ObjectIO', { - isValidValue: () => true, - supertype: null, - documentation: 'The root of the IO Type hierarchy', - toStateObject: coreObject => null, - fromStateObject: stateObject => null, - stateToArgsForConstructor: stateObject => [], - applyState: ( coreObject, stateObject ) => { }, - metadataKeys: [ - 'phetioTypeName', - 'phetioDocumentation', - 'phetioState', - 'phetioReadOnly', - 'phetioEventType', - 'phetioHighFrequency', - 'phetioPlayback', - 'phetioStudioControl', - 'phetioDynamicElement', - 'phetioIsArchetype', - 'phetioFeatured', - 'phetioArchetypePhetioID' // though this will only be present for dynamic elements - ] -} ); - -// @public -IOType.ObjectIO = ObjectIO; /** * @typedef {Object} MethodObject Index: studio/js/PhetioElement.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/studio/js/PhetioElement.js b/studio/js/PhetioElement.js --- a/studio/js/PhetioElement.js (revision be2c9e55d0de683bd9435376b95b35fc509cfa0e) +++ b/studio/js/PhetioElement.js (date 1617991429788) @@ -32,7 +32,7 @@ assert && assert( typeof this.typeName === 'string', 'type name should be a string' ); // @public (read-only) - what typeName should be used to create the view for this PhetioElement. Archetypes aren't - // interoperable, so just do the basic view that IOType.ObjectIO makes. + // interoperable, so just do the basic view that PhetioObject.ObjectIO makes. this.creatorTypeName = isArchetypeElement ? 'ObjectIO' : this.typeName; // @public (read-only) - metadata values can still be changed from the admin panel. see PhetioElementView.js Index: forces-and-motion-basics/js/netforce/model/Knot.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/forces-and-motion-basics/js/netforce/model/Knot.js b/forces-and-motion-basics/js/netforce/model/Knot.js --- a/forces-and-motion-basics/js/netforce/model/Knot.js (revision 0c3996362d0eb5c21f0ce7f00fc9b3fcb34a31a6) +++ b/forces-and-motion-basics/js/netforce/model/Knot.js (date 1617991429851) @@ -86,7 +86,7 @@ Knot.KnotIO = new IOType( 'KnotIO', { valueType: Knot, - supertype: ReferenceIO( IOType.ObjectIO ) + supertype: ReferenceIO( PhetioObject.ObjectIO ) } ); export default Knot; Index: studio/js/PhetioElementView.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/studio/js/PhetioElementView.js b/studio/js/PhetioElementView.js --- a/studio/js/PhetioElementView.js (revision be2c9e55d0de683bd9435376b95b35fc509cfa0e) +++ b/studio/js/PhetioElementView.js (date 1617991429951) @@ -26,7 +26,7 @@ import StudioUtils from './StudioUtils.js'; // constants -// This map holds all studio supported metadata elements (except phetioDocumentation which is handled by IOType.ObjectIO's creator +// This map holds all studio supported metadata elements (except phetioDocumentation which is handled by PhetioObject.ObjectIO's creator // Even if editable, studio must be in admin mode for these to have interactive UI. const STUDIO_SUPPORTED_METADATA_KEYS = { phetioDocumentation: { editable: true, displayName: '' }, Index: molecule-polarity/js/realmolecules/model/RealMolecule.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/molecule-polarity/js/realmolecules/model/RealMolecule.js b/molecule-polarity/js/realmolecules/model/RealMolecule.js --- a/molecule-polarity/js/realmolecules/model/RealMolecule.js (revision 29597ef2e83edc7e13deeeac4cbd01cb5a034a0e) +++ b/molecule-polarity/js/realmolecules/model/RealMolecule.js (date 1617991429961) @@ -42,7 +42,7 @@ RealMolecule.RealMoleculeIO = new IOType( 'RealMoleculeIO', { valueType: RealMolecule, - supertype: ReferenceIO( IOType.ObjectIO ) + supertype: ReferenceIO( PhetioObject.ObjectIO ) } ); moleculePolarity.register( 'RealMolecule', RealMolecule ); Index: tandem/js/PhetioGroupTests.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tandem/js/PhetioGroupTests.js b/tandem/js/PhetioGroupTests.js --- a/tandem/js/PhetioGroupTests.js (revision 33796537fb0ee85d96f2a9119978ea01740cca85) +++ b/tandem/js/PhetioGroupTests.js (date 1617991660424) @@ -9,7 +9,6 @@ import PhetioGroup from './PhetioGroup.js'; import PhetioObject from './PhetioObject.js'; import Tandem from './Tandem.js'; -import IOType from './types/IOType.js'; QUnit.module( 'PhetioGroup' ); @@ -25,7 +24,7 @@ }; const phetioGroup = new PhetioGroup( createElement, [ '' ], { tandem: Tandem.ROOT_TEST.createTandem( 'phetioGroup' ), - phetioType: PhetioGroup.PhetioGroupIO( IOType.ObjectIO ) + phetioType: PhetioGroup.PhetioGroupIO( PhetioObject.ObjectIO ) } ); phetioGroup.elementCreatedEmitter.addListener( element => { @@ -72,7 +71,7 @@ }; const myPhetioGroup = new PhetioGroup( createElement, [], { tandem: Tandem.ROOT_TEST.createTandem( 'myPhetioGroup' ), - phetioType: PhetioGroup.PhetioGroupIO( IOType.ObjectIO ) + phetioType: PhetioGroup.PhetioGroupIO( PhetioObject.ObjectIO ) } ); let creationCount = 0; Index: phet-io/js/phetioCommandProcessor.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io/js/phetioCommandProcessor.js b/phet-io/js/phetioCommandProcessor.js --- a/phet-io/js/phetioCommandProcessor.js (revision e662b42a4914f221077da1c55b0485f357a7f1c8) +++ b/phet-io/js/phetioCommandProcessor.js (date 1617991429943) @@ -250,9 +250,9 @@ if ( type.methods && type.methods[ method ] ) { return type.methods[ method ]; } - else if ( type === IOType.ObjectIO ) { + else if ( type === PhetioObject.ObjectIO ) { - // Already checked IOType.ObjectIO for methods, cannot go further up the chain. + // Already checked PhetioObject.ObjectIO for methods, cannot go further up the chain. return null; } else { Index: energy-forms-and-changes/js/intro/view/EFACIntroScreenView.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/energy-forms-and-changes/js/intro/view/EFACIntroScreenView.js b/energy-forms-and-changes/js/intro/view/EFACIntroScreenView.js --- a/energy-forms-and-changes/js/intro/view/EFACIntroScreenView.js (revision 82f0c3b2133b9a22b4eb9fff4a414a5e80cdfd4f) +++ b/energy-forms-and-changes/js/intro/view/EFACIntroScreenView.js (date 1617991660418) @@ -35,8 +35,8 @@ import Checkbox from '../../../../sun/js/Checkbox.js'; import Panel from '../../../../sun/js/Panel.js'; import PhetioGroup from '../../../../tandem/js/PhetioGroup.js'; +import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import Tandem from '../../../../tandem/js/Tandem.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import Animation from '../../../../twixt/js/Animation.js'; import Easing from '../../../../twixt/js/Easing.js'; @@ -449,7 +449,7 @@ }, [ model.beakerGroup.archetype ], { tandem: tandem.createTandem( 'beakerProxyNodeGroup' ), - phetioType: PhetioGroup.PhetioGroupIO( ReferenceIO( IOType.ObjectIO ) ), + phetioType: PhetioGroup.PhetioGroupIO( ReferenceIO( PhetioObject.ObjectIO ) ), inputEnabledPropertyPhetioInstrumented: true, supportsDynamicState: false } ); Index: beers-law-lab/js/beerslaw/model/BeersLawSolution.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/beers-law-lab/js/beerslaw/model/BeersLawSolution.js b/beers-law-lab/js/beerslaw/model/BeersLawSolution.js --- a/beers-law-lab/js/beerslaw/model/BeersLawSolution.js (revision 985bbbd5e8d3bc3077d0705ec6a587da12f4c057) +++ b/beers-law-lab/js/beerslaw/model/BeersLawSolution.js (date 1617991429959) @@ -148,7 +148,7 @@ */ BeersLawSolution.BeersLawSolutionIO = new IOType( 'BeersLawSolutionIO', { valueType: BeersLawSolution, - supertype: ReferenceIO( IOType.ObjectIO ), + supertype: ReferenceIO( PhetioObject.ObjectIO ), documentation: 'A solution in the Beer\'s Law screen' } ); Index: gravity-and-orbits/js/common/model/GravityAndOrbitsModel.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/gravity-and-orbits/js/common/model/GravityAndOrbitsModel.js b/gravity-and-orbits/js/common/model/GravityAndOrbitsModel.js --- a/gravity-and-orbits/js/common/model/GravityAndOrbitsModel.js (revision 2ed8ecb07c1e16ed65092c49dbf9ce814e3e447f) +++ b/gravity-and-orbits/js/common/model/GravityAndOrbitsModel.js (date 1617991660516) @@ -18,8 +18,8 @@ import Property from '../../../../axon/js/Property.js'; import PhysicalConstants from '../../../../phet-core/js/PhysicalConstants.js'; import TimeSpeed from '../../../../scenery-phet/js/TimeSpeed.js'; +import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import Tandem from '../../../../tandem/js/Tandem.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import gravityAndOrbits from '../../gravityAndOrbits.js'; @@ -73,7 +73,7 @@ this.sceneProperty = new Property( this.sceneList.scenes[ 0 ], { tandem: tandem.createTandem( 'sceneProperty' ), validValues: this.sceneList.scenes, - phetioType: Property.PropertyIO( ReferenceIO( IOType.ObjectIO ) ) + phetioType: Property.PropertyIO( ReferenceIO( PhetioObject.ObjectIO ) ) } ); } Index: tandem/js/PhetioConstants.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tandem/js/PhetioConstants.js b/tandem/js/PhetioConstants.js --- a/tandem/js/PhetioConstants.js (revision 33796537fb0ee85d96f2a9119978ea01740cca85) +++ b/tandem/js/PhetioConstants.js (date 1617991429812) @@ -4,7 +4,7 @@ /** * Constants used in PhET-iO. Defined in the tandem repo since they need to be accessed in non-private code, like - * IOType.ObjectIO. + * PhetioObject.ObjectIO. * @author Sam Reid (PhET Interactive Simulations) */ const PhetioConstants = { Index: energy-forms-and-changes/js/common/view/BeakerView.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/energy-forms-and-changes/js/common/view/BeakerView.js b/energy-forms-and-changes/js/common/view/BeakerView.js --- a/energy-forms-and-changes/js/common/view/BeakerView.js (revision 82f0c3b2133b9a22b4eb9fff4a414a5e80cdfd4f) +++ b/energy-forms-and-changes/js/common/view/BeakerView.js (date 1617991660484) @@ -22,7 +22,6 @@ import RichText from '../../../../scenery/js/nodes/RichText.js'; import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import Tandem from '../../../../tandem/js/Tandem.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import energyFormsAndChanges from '../../energyFormsAndChanges.js'; import energyFormsAndChangesStrings from '../../energyFormsAndChangesStrings.js'; @@ -56,7 +55,7 @@ // phet-io tandem: Tandem.REQUIRED, - phetioType: ReferenceIO( IOType.ObjectIO ) + phetioType: ReferenceIO( PhetioObject.ObjectIO ) }, options ); super( options ); Index: natural-selection/js/common/model/Gene.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/natural-selection/js/common/model/Gene.js b/natural-selection/js/common/model/Gene.js --- a/natural-selection/js/common/model/Gene.js (revision 6bbc2ea02affc16b5a2196727962d301716f50c8) +++ b/natural-selection/js/common/model/Gene.js (date 1617991429955) @@ -233,7 +233,7 @@ */ Gene.GeneIO = new IOType( 'GeneIO', { valueType: Gene, - supertype: ReferenceIO( IOType.ObjectIO ) + supertype: ReferenceIO( PhetioObject.ObjectIO ) } ); naturalSelection.register( 'Gene', Gene ); Index: tandem/js/PhetioObject.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tandem/js/PhetioObject.js b/tandem/js/PhetioObject.js --- a/tandem/js/PhetioObject.js (revision 33796537fb0ee85d96f2a9119978ea01740cca85) +++ b/tandem/js/PhetioObject.js (date 1617991660471) @@ -45,7 +45,7 @@ tandem: Tandem.OPTIONAL, // Defines API methods, events and serialization - phetioType: IOType.ObjectIO, + phetioType: PhetioObject.ObjectIO, // {string} Useful notes about an instrumented PhetioObject, shown in the PhET-iO Studio Wrapper. It's an html // string, so "
" tags are required instead of "\n" characters for proper rendering in Studio @@ -656,6 +656,31 @@ 'phetioArchetypePhetioID' ]; +// @public - base type for the IOType hierarchy +PhetioObject.ObjectIO = new IOType( 'ObjectIO', { + isValidValue: () => true, + supertype: null, + documentation: 'The root of the IO Type hierarchy', + toStateObject: coreObject => null, + fromStateObject: stateObject => null, + stateToArgsForConstructor: stateObject => [], + applyState: ( coreObject, stateObject ) => { }, + metadataKeys: [ + 'phetioTypeName', + 'phetioDocumentation', + 'phetioState', + 'phetioReadOnly', + 'phetioEventType', + 'phetioHighFrequency', + 'phetioPlayback', + 'phetioStudioControl', + 'phetioDynamicElement', + 'phetioIsArchetype', + 'phetioFeatured', + 'phetioArchetypePhetioID' // though this will only be present for dynamic elements + ] +} ); + /** * Determine if any of the options keys are intended for PhetioObject. Semantically equivalent to * _.intersection( _.keys( options ), _.keys( DEFAULTS) ).length>0 but implemented imperatively to avoid memory or Index: energy-forms-and-changes/js/common/model/RectangularThermalMovableModelElement.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/energy-forms-and-changes/js/common/model/RectangularThermalMovableModelElement.js b/energy-forms-and-changes/js/common/model/RectangularThermalMovableModelElement.js --- a/energy-forms-and-changes/js/common/model/RectangularThermalMovableModelElement.js (revision 82f0c3b2133b9a22b4eb9fff4a414a5e80cdfd4f) +++ b/energy-forms-and-changes/js/common/model/RectangularThermalMovableModelElement.js (date 1617991660457) @@ -16,8 +16,8 @@ import Vector2 from '../../../../dot/js/Vector2.js'; import Shape from '../../../../kite/js/Shape.js'; import merge from '../../../../phet-core/js/merge.js'; +import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import Tandem from '../../../../tandem/js/Tandem.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import energyFormsAndChanges from '../../energyFormsAndChanges.js'; import EFACConstants from '../EFACConstants.js'; @@ -194,7 +194,7 @@ // chunks in the view this.slices = createObservableArray( { tandem: options.tandem.createTandem( 'slices' ), - phetioType: createObservableArray.ObservableArrayIO( ReferenceIO( IOType.ObjectIO ) ) + phetioType: createObservableArray.ObservableArrayIO( ReferenceIO( PhetioObject.ObjectIO ) ) } ); // add the slices Index: balancing-act/js/balancelab/model/BalanceLabModel.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/balancing-act/js/balancelab/model/BalanceLabModel.js b/balancing-act/js/balancelab/model/BalanceLabModel.js --- a/balancing-act/js/balancelab/model/BalanceLabModel.js (revision 84423a7364b6780d8379661458b73cbd8c00a532) +++ b/balancing-act/js/balancelab/model/BalanceLabModel.js (date 1617991456662) @@ -9,7 +9,7 @@ import Vector2 from '../../../../dot/js/Vector2.js'; import PhetioGroup from '../../../../tandem/js/PhetioGroup.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; +import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import balancingAct from '../../balancingAct.js'; import BalanceModel from '../../common/model/BalanceModel.js'; @@ -36,7 +36,7 @@ }, [ 1, Vector2.ZERO ], { tandem: tandem.createTandem( 'brickStackGroup' ), - phetioType: PhetioGroup.PhetioGroupIO( ReferenceIO( IOType.ObjectIO ) ) + phetioType: PhetioGroup.PhetioGroupIO( ReferenceIO( PhetioObject.ObjectIO ) ) } ); // @public {PhetioGroup.} @@ -51,7 +51,7 @@ }, [ Vector2.ZERO, 0 ], { tandem: tandem.createTandem( 'mysteryMassGroup' ), - phetioType: PhetioGroup.PhetioGroupIO( ReferenceIO( IOType.ObjectIO ) ) + phetioType: PhetioGroup.PhetioGroupIO( ReferenceIO( PhetioObject.ObjectIO ) ) } ); // TODO: Add person group here too, see https://github.com/phetsims/balancing-act/issues/99 Index: shred/js/model/Particle.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/shred/js/model/Particle.js b/shred/js/model/Particle.js --- a/shred/js/model/Particle.js (revision 8ed81fcd47d8b87beaa485f053b123f149fd17ed) +++ b/shred/js/model/Particle.js (date 1617991429861) @@ -154,7 +154,7 @@ Particle.ParticleIO = new IOType( 'ParticleIO', { valueType: Particle, documentation: 'The model for a single particle such as an electron, proton, or neutron.', - supertype: ReferenceIO( IOType.ObjectIO ) + supertype: ReferenceIO( PhetioObject.ObjectIO ) } ); shred.register( 'Particle', Particle ); Index: joist/js/Screen.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/joist/js/Screen.js b/joist/js/Screen.js --- a/joist/js/Screen.js (revision 728803d851998c1c4a25792ddad31c8583010c2d) +++ b/joist/js/Screen.js (date 1617991429796) @@ -353,7 +353,7 @@ Screen.ScreenIO = new IOType( 'ScreenIO', { valueType: Screen, - supertype: ReferenceIO( IOType.ObjectIO ), + supertype: ReferenceIO( PhetioObject.ObjectIO ), documentation: 'Section of a simulation which has its own model and view.' } ); Index: energy-forms-and-changes/js/common/model/ModelElement.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/energy-forms-and-changes/js/common/model/ModelElement.js b/energy-forms-and-changes/js/common/model/ModelElement.js --- a/energy-forms-and-changes/js/common/model/ModelElement.js (revision 82f0c3b2133b9a22b4eb9fff4a414a5e80cdfd4f) +++ b/energy-forms-and-changes/js/common/model/ModelElement.js (date 1617991660433) @@ -13,7 +13,6 @@ import merge from '../../../../phet-core/js/merge.js'; import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import Tandem from '../../../../tandem/js/Tandem.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import energyFormsAndChanges from '../../energyFormsAndChanges.js'; @@ -27,7 +26,7 @@ options = merge( { tandem: Tandem.REQUIRED, - phetioType: ReferenceIO( IOType.ObjectIO ), + phetioType: ReferenceIO( PhetioObject.ObjectIO ), positionPropertyOptions: { units: 'm', phetioHighFrequency: true, Index: beers-law-lab/js/common/model/Solute.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/beers-law-lab/js/common/model/Solute.js b/beers-law-lab/js/common/model/Solute.js --- a/beers-law-lab/js/common/model/Solute.js (revision 985bbbd5e8d3bc3077d0705ec6a587da12f4c057) +++ b/beers-law-lab/js/common/model/Solute.js (date 1617991429916) @@ -102,7 +102,7 @@ */ Solute.SoluteIO = new IOType( 'SoluteIO', { valueType: Solute, - supertype: ReferenceIO( IOType.ObjectIO ), + supertype: ReferenceIO( PhetioObject.ObjectIO ), documentation: 'A solute in the Concentration screen' } ); Index: phet-io/doc/phet-io-instrumentation-technical-guide.md IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io/doc/phet-io-instrumentation-technical-guide.md b/phet-io/doc/phet-io-instrumentation-technical-guide.md --- a/phet-io/doc/phet-io-instrumentation-technical-guide.md (revision e662b42a4914f221077da1c55b0485f357a7f1c8) +++ b/phet-io/doc/phet-io-instrumentation-technical-guide.md (date 1617991429803) @@ -373,7 +373,7 @@ determine what your IO Type should look like. * If there are any, public methods will be defined in this IO Type. * If there are any, custom events that this IO Type can emit to the data stream will be defined here. -* Know that `IOType.ObjectIO`, as the root of the IO Type hierarchy, can be a great resource as place for documentation +* Know that `PhetioObject.ObjectIO`, as the root of the IO Type hierarchy, can be a great resource as place for documentation about each possible piece of an IO Type. * If the element for this IO Type does not need to be stateful, then you can ignore implementing the static methods needed for serialization. @@ -410,7 +410,7 @@ * `ReferenceIO` will add reference-type-serialization logic to its parameter. See [Serialization](https://github.com/phetsims/phet-io/blob/master/doc/phet-io-instrumentation-technical-guide.md#serialization) for more details. `ReferenceIO` can also be extended if an IO Type only needs to support reference-type serialization, see -usages of `extends ReferenceIO( IOType.ObjectIO )`. +usages of `extends ReferenceIO( PhetioObject.ObjectIO )`. ### Serialization Index: ph-scale/js/common/model/Solute.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/ph-scale/js/common/model/Solute.js b/ph-scale/js/common/model/Solute.js --- a/ph-scale/js/common/model/Solute.js (revision b72b40725c7ed74b08a3d39b0543614376ae5349) +++ b/ph-scale/js/common/model/Solute.js (date 1617991429871) @@ -132,10 +132,10 @@ */ Solute.SoluteIO = new IOType( 'SoluteIO', { valueType: Solute, - supertype: ReferenceIO( IOType.ObjectIO ), + supertype: ReferenceIO( PhetioObject.ObjectIO ), toStateObject: solute => { - const soluteReference = ReferenceIO( IOType.ObjectIO ).toStateObject( solute ); + const soluteReference = ReferenceIO( PhetioObject.ObjectIO ).toStateObject( solute ); soluteReference.name = solute.name; soluteReference.pH = solute.pH; return soluteReference; Index: molarity/js/molarity/model/Solute.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/molarity/js/molarity/model/Solute.js b/molarity/js/molarity/model/Solute.js --- a/molarity/js/molarity/model/Solute.js (revision b3b4728322bd33fa213f48f488e5b287429555fd) +++ b/molarity/js/molarity/model/Solute.js (date 1617991429894) @@ -51,7 +51,7 @@ Solute.SoluteIO = new IOType( 'SoluteIO', { valueType: Solute, documentation: 'The solute for the sim', - supertype: ReferenceIO( IOType.ObjectIO ) + supertype: ReferenceIO( PhetioObject.ObjectIO ) } ); export default Solute; \ No newline at end of file Index: natural-selection/js/common/model/Allele.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/natural-selection/js/common/model/Allele.js b/natural-selection/js/common/model/Allele.js --- a/natural-selection/js/common/model/Allele.js (revision 6bbc2ea02affc16b5a2196727962d301716f50c8) +++ b/natural-selection/js/common/model/Allele.js (date 1617991429906) @@ -75,7 +75,7 @@ */ Allele.AlleleIO = new IOType( 'AlleleIO', { valueType: Allele, - supertype: ReferenceIO( IOType.ObjectIO ) + supertype: ReferenceIO( PhetioObject.ObjectIO ) } ); // Static instances Index: phet-io/js/phetioEngine.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phet-io/js/phetioEngine.js b/phet-io/js/phetioEngine.js --- a/phet-io/js/phetioEngine.js (revision e662b42a4914f221077da1c55b0485f357a7f1c8) +++ b/phet-io/js/phetioEngine.js (date 1617991429880) @@ -312,7 +312,7 @@ * @private */ getAPIForType( type ) { - assert && assert( type !== window.Object, 'ObjectIO inherits Object, but getAPIForType only supports IOType.ObjectIO and subtypes' ); + assert && assert( type !== window.Object, 'ObjectIO inherits Object, but getAPIForType only supports PhetioObject.ObjectIO and subtypes' ); const mapAPIForType = parameterType => parameterType.typeName; Index: charges-and-fields/js/charges-and-fields/view/ElectricPotentialLinesNode.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/charges-and-fields/js/charges-and-fields/view/ElectricPotentialLinesNode.js b/charges-and-fields/js/charges-and-fields/view/ElectricPotentialLinesNode.js --- a/charges-and-fields/js/charges-and-fields/view/ElectricPotentialLinesNode.js (revision 9b7bd8584263f606fd0029853e02e0b83ba15b80) +++ b/charges-and-fields/js/charges-and-fields/view/ElectricPotentialLinesNode.js (date 1617991660489) @@ -7,7 +7,7 @@ import Node from '../../../../scenery/js/nodes/Node.js'; import PhetioGroup from '../../../../tandem/js/PhetioGroup.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; +import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import chargesAndFields from '../../chargesAndFields.js'; import ElectricPotentialLineView from './ElectricPotentialLineView.js'; @@ -46,7 +46,7 @@ return new ElectricPotentialLineView( electricPotentialLine, modelViewTransform, tandem ); }, [ electricPotentialLineGroup.archetype ], { tandem: tandem.createTandem( 'electricPotentialLineViewGroup' ), - phetioType: PhetioGroup.PhetioGroupIO( IOType.ObjectIO ), + phetioType: PhetioGroup.PhetioGroupIO( PhetioObject.ObjectIO ), // These elements are not created by the PhET-IO state engine, they can just listen to the model for supporting // state in the same way they do for sim logic. Index: forces-and-motion-basics/js/motion/model/Item.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/forces-and-motion-basics/js/motion/model/Item.js b/forces-and-motion-basics/js/motion/model/Item.js --- a/forces-and-motion-basics/js/motion/model/Item.js (revision 0c3996362d0eb5c21f0ce7f00fc9b3fcb34a31a6) +++ b/forces-and-motion-basics/js/motion/model/Item.js (date 1617991660443) @@ -15,7 +15,6 @@ import Vector2 from '../../../../dot/js/Vector2.js'; import Vector2Property from '../../../../dot/js/Vector2Property.js'; import PhetioObject from '../../../../tandem/js/PhetioObject.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; import ObjectLiteralIO from '../../../../tandem/js/types/ObjectLiteralIO.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import forcesAndMotionBasics from '../../forcesAndMotionBasics.js'; @@ -41,7 +40,7 @@ */ constructor( context, name, tandem, image, mass, x, y, imageScale, homeScale, pusherInset, sittingImage, holdingImage, mystery ) { - super( { tandem: tandem, phetioType: ReferenceIO( IOType.ObjectIO ) } ); + super( { tandem: tandem, phetioType: ReferenceIO( PhetioObject.ObjectIO ) } ); this.name = name; Index: balancing-act/js/common/model/Mass.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/balancing-act/js/common/model/Mass.js b/balancing-act/js/common/model/Mass.js --- a/balancing-act/js/common/model/Mass.js (revision 84423a7364b6780d8379661458b73cbd8c00a532) +++ b/balancing-act/js/common/model/Mass.js (date 1617991456668) @@ -11,7 +11,6 @@ import merge from '../../../../phet-core/js/merge.js'; import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import Tandem from '../../../../tandem/js/Tandem.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import balancingAct from '../../balancingAct.js'; @@ -26,7 +25,7 @@ options = merge( { tandem: Tandem.REQUIRED, - phetioType: ReferenceIO( IOType.ObjectIO ) + phetioType: ReferenceIO( PhetioObject.ObjectIO ) }, options ); // instrumented so it can be phetioDynamicElement: true for PhetioGroups Index: forces-and-motion-basics/js/motion/model/MotionModel.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/forces-and-motion-basics/js/motion/model/MotionModel.js b/forces-and-motion-basics/js/motion/model/MotionModel.js --- a/forces-and-motion-basics/js/motion/model/MotionModel.js (revision 0c3996362d0eb5c21f0ce7f00fc9b3fcb34a31a6) +++ b/forces-and-motion-basics/js/motion/model/MotionModel.js (date 1617991660496) @@ -7,15 +7,15 @@ */ import BooleanProperty from '../../../../axon/js/BooleanProperty.js'; +import createObservableArray from '../../../../axon/js/createObservableArray.js'; import DerivedProperty from '../../../../axon/js/DerivedProperty.js'; import Emitter from '../../../../axon/js/Emitter.js'; import NumberProperty from '../../../../axon/js/NumberProperty.js'; -import createObservableArray from '../../../../axon/js/createObservableArray.js'; import StringProperty from '../../../../axon/js/StringProperty.js'; import Range from '../../../../dot/js/Range.js'; import Utils from '../../../../dot/js/Utils.js'; import Vector2 from '../../../../dot/js/Vector2.js'; -import IOType from '../../../../tandem/js/types/IOType.js'; +import PhetioObject from '../../../../tandem/js/PhetioObject.js'; import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js'; import crateImage from '../../../images/crate_png.js'; import fridgeImage from '../../../images/fridge_png.js'; @@ -52,7 +52,7 @@ const frictionValue = screen === 'motion' ? 0 : MotionConstants.MAX_FRICTION / 2; this.stack = createObservableArray( { tandem: tandem.createTandem( 'stackObservableArray' ), - phetioType: createObservableArray.ObservableArrayIO( ReferenceIO( IOType.ObjectIO ) ) + phetioType: createObservableArray.ObservableArrayIO( ReferenceIO( PhetioObject.ObjectIO ) ) } ); // @public - force applied to the stack of items by the pusher ```
samreid commented 3 years ago

Here's a patch that moves out the defaults for reuse in PhetioObject and IOType:

```diff Index: main/tandem/js/PhetioObject.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/main/tandem/js/PhetioObject.js b/main/tandem/js/PhetioObject.js --- a/main/tandem/js/PhetioObject.js (revision bbce01446785be1b80a55b785d63a5619aeedb20) +++ b/main/tandem/js/PhetioObject.js (date 1617999720388) @@ -21,6 +21,7 @@ import LinkedElementIO from './LinkedElementIO.js'; import phetioAPIValidation from './phetioAPIValidation.js'; import Tandem from './Tandem.js'; +import TandemConstants from './TandemConstants.js'; import tandemNamespace from './tandemNamespace.js'; import IOType from './types/IOType.js'; @@ -49,41 +50,37 @@ // {string} Useful notes about an instrumented PhetioObject, shown in the PhET-iO Studio Wrapper. It's an html // string, so "
" tags are required instead of "\n" characters for proper rendering in Studio - phetioDocumentation: '', + phetioDocumentation: TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS.phetioDocumentation, // When true, includes the PhetioObject in the PhET-iO state (not automatically recursive, must be specified for // children explicitly) - phetioState: true, + phetioState: TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS.phetioState, // This option controls how PhET-iO wrappers can interface with this PhetioObject. Predominately this occurs via // public methods defined on this PhetioObject's phetioType, in which some method are not executable when this flag // is true. See `ObjectIO.methods` for further documentation, especially regarding `invocableForReadOnlyElements`. - phetioReadOnly: false, + phetioReadOnly: TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS.phetioReadOnly, // Category of event type, can be overridden in phetioStartEvent options - phetioEventType: EventType.MODEL, + phetioEventType: TandemConstants.DEFAULT_EVENT_TYPE, // High frequency events such as mouse moves can be omitted from data stream, see ?phetioEmitHighFrequencyEvents // and Client.launchSim option - phetioHighFrequency: false, + phetioHighFrequency: TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS.phetioHighFrequency, // When true, emits events for data streams for playback, see handlePlaybackEvent.js - phetioPlayback: false, + phetioPlayback: TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS.phetioPlayback, // When true, Studio is allowed to create a control for this PhetioObject (if it knows how) - phetioStudioControl: true, + phetioStudioControl: TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS.phetioStudioControl, // When true, this is categorized as an important "featured" element in Studio. - phetioFeatured: false, - - // {Object|null} optional - delivered with each event, if specified. phetioPlayback is appended here, if true. - // Note: unlike other options, this option can be mutated downstream, and hence should be created newly for each instance. - phetioEventMetadata: null, + phetioFeatured: TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS.phetioFeatured, // {boolean} optional - indicates that an object may or may not have been created. Applies recursively automatically // and should only be set manually on the root dynamic element. Dynamic archetypes will have this overwritten to // false even if explicitly provided as true, as archetypes cannot be dynamic. - phetioDynamicElement: false, + phetioDynamicElement: TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS.phetioDynamicElement, // {boolean} Marking phetioDesigned: true opts-in to API change detection tooling that can be used to catch inadvertent // changes to a designed API. A phetioDesigned:true PhetioObject (or any of its tandem descendants) will throw @@ -91,8 +88,13 @@ // (a) its package.json lists compareDesignedAPIChanges:true in the "phet-io" section // (b) the simulation is listed in perennial/data/phet-io-api-stable // (c) any of its metadata values deviate from the reference API - phetioDesigned: false + phetioDesigned: TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS.phetioDesigned, + + // {Object|null} optional - delivered with each event, if specified. phetioPlayback is appended here, if true. + // Note: unlike other options, this option can be mutated downstream, and hence should be created newly for each instance. + phetioEventMetadata: null }; + class PhetioObject { /** Index: main/phet-core/js/EnumerationIO.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/main/phet-core/js/EnumerationIO.js b/main/phet-core/js/EnumerationIO.js --- a/main/phet-core/js/EnumerationIO.js (revision 1c57e441cce0cb5074855224ebc324dcbbcd4c70) +++ b/main/phet-core/js/EnumerationIO.js (date 1617999640750) @@ -24,7 +24,10 @@ assert && assert( enumeration instanceof Enumeration, 'enumeration must be an Enumeration' ); if ( !cache.has( enumeration ) ) { + + // NOTE: TandemConstants duplicates this implementation, do not change without updating that as well. const toStateObjectImpl = v => v.name; + const valueNames = enumeration.VALUES.map( toStateObjectImpl ); // Enumeration supports additional documentation, so the values can be described. Index: main/tandem/js/TandemConstants.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/main/tandem/js/TandemConstants.js b/main/tandem/js/TandemConstants.js new file mode 100644 --- /dev/null (date 1617999978487) +++ b/main/tandem/js/TandemConstants.js (date 1617999978487) @@ -0,0 +1,38 @@ +// Copyright 2020, University of Colorado Boulder + +import EventType from './EventType.js'; +import tandemNamespace from './tandemNamespace.js'; + +/** + * + * @author Sam Reid (PhET Interactive Simulations) + */ + +class TandemConstants { +} + +TandemConstants.OBJECT_IO_TYPE_NAME = 'ObjectIO'; +TandemConstants.DEFAULT_EVENT_TYPE = EventType.MODEL; + +// Default metadata set for an ObjectIO in the PhET-iO API. These are used as the default options in PhetioObject +// and when outputting an API (since values that match the defaults are omitted) +TandemConstants.PHET_IO_OBJECT_METADATA_DEFAULTS = { + phetioTypeName: TandemConstants.OBJECT_IO_TYPE_NAME, + phetioDocumentation: '', + phetioState: true, + phetioReadOnly: false, + + // NOTE: Relies on the details about how Enumerations are serialized (via name), like EventType.phetioType.toStateObject( object.phetioEventType ) + phetioEventType: TandemConstants.DEFAULT_EVENT_TYPE.name, + phetioHighFrequency: false, + phetioPlayback: false, + phetioStudioControl: true, + phetioDynamicElement: false, + phetioIsArchetype: false, + phetioFeatured: false, + phetioDesigned: false, + phetioArchetypePhetioID: null +}; + +tandemNamespace.register( 'TandemConstants', TandemConstants ); +export default TandemConstants; \ No newline at end of file ```
zepumph commented 3 years ago

The above is not ideal, but we think it will work better than other ideas:

zepumph commented 3 years ago

We will continue with the above patch, to be applied over in https://github.com/phetsims/phet-io/issues/1753, closing