Skip to content

Commit

Permalink
update PhetioObject.phetioStartEvent to support a function that retur…
Browse files Browse the repository at this point in the history
…ns args, #62
  • Loading branch information
zepumph committed Oct 3, 2018
1 parent 6c14e49 commit 0db3d72
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion js/PhetioObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,14 @@ define( function( require ) {
* Start an event for the nested PhET-iO event stream.
*
* @param {string} event - the name of the event
* @param {Object} [args] - arguments for the event
* @param {Object|function} [args] - arguments for the event, either an object, or a function that returns an object
* @param {Object} [options] - options for firing the event
* @public
*/
phetioStartEvent: function( event, args, options ) {
assert && assert( this.phetioObjectInitialized, 'phetioObject should be initialized' );
assert && assert( typeof event === 'string' );
assert && args && assert( typeof args === 'object' || typeof args === 'function' );

// Poor-man's options for maximum performance
options = options || DEFAULT_EVENT_OPTIONS;
Expand All @@ -178,6 +180,11 @@ define( function( require ) {
}

if ( this.tandem.isSuppliedAndEnabled() ) {

// Only get the args if we are actually going to send the event.
if ( typeof args === 'function' ) {
args = args();
}
this.phetioMessageStack.push( phetioEvents.start( eventType, this, event, args ) );
}
},
Expand Down

0 comments on commit 0db3d72

Please sign in to comment.