From 0db3d72113261c8b52f0e7de4134a4f5a9244ef2 Mon Sep 17 00:00:00 2001 From: zepumph Date: Wed, 3 Oct 2018 09:47:48 -0800 Subject: [PATCH] update PhetioObject.phetioStartEvent to support a function that returns args, https://github.com/phetsims/tandem/issues/62 --- js/PhetioObject.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/PhetioObject.js b/js/PhetioObject.js index a452edc6..81e53633 100644 --- a/js/PhetioObject.js +++ b/js/PhetioObject.js @@ -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; @@ -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 ) ); } },