IOType¶
Overview¶
IOTypes form a synthetic type system used to describe PhET-iO Elements. A PhET-iO Element is an instrumented PhetioObject that is interoperable from the "wrapper" frame (outside the sim frame). An IOType includes documentation, methods, names, serialization, etc.
@author Sam Reid (PhET Interactive Simulations)
Class IOType¶
StateType is the whole thing, SelfStateType is just at this level export default class IOType<T = any, SelfStateType = any, ParentStateType = EmptyParent, StateType extends SelfStateType & ParentStateType = SelfStateType & ParentStateType> { // eslint-disable-line typescript-eslint/no-explicit-any
Constructor¶
new IOType( typeName : IOTypeName, providedOptions : IOTypeOptions<T, StateType, SelfStateType> )¶
Instance Methods¶
toStateObject( coreObject : T ) : StateType¶
fromStateObject( stateObject : StateType ) : T¶
applyState( coreObject : T, stateObject : StateType )¶
stateObjectToCreateElementArguments( stateObject : StateType ) : unknown[]¶
extends( type : IOType<unknown, unknown> ) : boolean¶
Returns true if this IOType is a subtype of the passed-in type (or if they are the same).
getAllMetadataDefaults() : Partial<PhetioElementMetadata>¶
Return all the metadata defaults (for the entire IOType hierarchy)
getAllDataDefaults() : Record<string, unknown>¶
Return all the data defaults (for the entire IOType hierarchy)
getAllAPIStateKeys() : APIStateKeys¶
Return all the apiStateKeys (for the entire IOType hierarchy) in one array.
toStateObjectForAPI( coreObject : T ) : StateType¶
Get the state object for a PhET-iO Element, but only the entries that should be tracked by the PhET-iO API. See StateSchema.apiStateKeys for details. This implementation sets a global to make sure that nested state also only selects the apiStateKeys for api tracking (PropertyIO<RangeIO> could have validValues of PointIO that shouldn't include non-tracked values of PointIO, if there are any).
isStateObjectValid( stateObject : StateType, toAssert, schemaKeysPresentInStateObject : string[] ) : boolean¶
@param stateObject - the stateObject to validate against @param toAssert=false - whether to assert when invalid @param schemaKeysPresentInStateObject=[] @returns if the stateObject is valid or not.
validateStateObject( stateObject : StateType )¶
Assert if the provided stateObject is not valid to this IOType's stateSchema
toString() : IOTypeName¶
getAPI() : PhetioType¶
Return an object that indicates the API type, including documentation, methods & signatures, supertypes, etc. The object is intended for serialization via JSON.stringify().
This function could be static, but that doesn't work well with the singleton pattern, so keep in on the prototype.
Instance Properties¶
supertype : IOType¶
(readonly)
See documentation in options type declaration
documentation : string¶
(readonly)
methods : Record<string, IOTypeMethod>¶
(readonly)
events : string[]¶
(readonly)
metadataDefaults : Partial<PhetioElementMetadata>¶
(readonly)
dataDefaults : Record<string, unknown>¶
(readonly)
methodOrder : string[]¶
(readonly)
parameterTypes : IOType[]¶
(readonly)
fromStateObjectOption : ( ( state: StateType ) => T ) | null¶
(readonly)
stateObjectToCreateElementArgumentsOption : ( ( s: StateType ) => unknown[] ) | null¶
(readonly)
TODO: instead of unknown this is the second parameter type for PhetioDynamicElementContainer. How? https://github.com/phetsims/tandem/issues/261
addChildElement : AddChildElement¶
(readonly)
validator : Validator<T>¶
(readonly)
defaultDeserializationMethod : DeserializationType¶
(readonly)
isFunctionType : boolean¶
(readonly)
stateSchema : StateSchema<T, SelfStateType> | null¶
(readonly)
The StateSchema (type) that the option is made into. The option is more flexible than the class.
Static Properties¶
ObjectIO : IOType¶
The base IOType for the entire hierarchy.