PhetioAction¶
Overview¶
An instrumented class that wraps a function that does "work" that needs to be interoperable with PhET-iO. PhetioAction supports the following features:
- Data stream support: The function will be wrapped in an
executed
event and added to the data stream, nesting subsequent events the action's "work" cascades to as child events. - Interopererability: PhetioActionIO supports the
execute
method so that PhetioAction instances can be executed from the PhET-iO wrapper. - It also has an emitter if you want to listen to when the action is done doing its work, https://github.com/phetsims/phet-io/issues/1543
@author Michael Kauzmann (PhET Interactive Simulations)
Class PhetioAction¶
Constructor¶
new PhetioAction( action : ( ...args: T ) => void, providedOptions? : ActionOptions )¶
Instance Methods¶
execute( ...args : T )¶
Invokes the action. @params - expected parameters are based on options.parameters, see constructor
dispose()¶
Note: Be careful about adding disposal logic directly to this function, it is likely preferred to add it to disposePhetioAction instead, see disposeOnExecuteCompletion for details.
Instance Properties¶
executedEmitter : Emitter<T>¶
(readonly)
To listen to when the action has completed.
Static Properties¶
PhetioActionIO¶
(readonly)
Type ActionOptions¶
StrictOmit<PhetioDataHandlerOptions, "phetioOuterType">
Source Code¶
See the source for PhetioAction.ts in the tandem repository.