From b383824934c744c1f312940c83e56657275f9766 Mon Sep 17 00:00:00 2001 From: zepumph Date: Fri, 24 Jul 2020 10:55:11 -0800 Subject: [PATCH] clear dynamic element containers based on `isStateInScope`, https://github.com/phetsims/tandem/issues/193 --- js/PhetioDynamicElementContainer.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/js/PhetioDynamicElementContainer.js b/js/PhetioDynamicElementContainer.js index 6017ffe0..6dee9c5a 100644 --- a/js/PhetioDynamicElementContainer.js +++ b/js/PhetioDynamicElementContainer.js @@ -122,16 +122,12 @@ class PhetioDynamicElementContainer extends PhetioObject { const phetioStateEngine = phet.phetio.phetioEngine.phetioStateEngine; // On state start, clear out the container and set to defer notifications. - phetioStateEngine.onBeforeStateSetEmitter.addListener( phetioIDsToSet => { - for ( let i = 0; i < phetioIDsToSet.length; i++ ) { - const phetioID = phetioIDsToSet[ i ]; - if ( phetioID.startsWith( this.tandem.phetioID ) ) { - - // specify that this is from state setting - this.clear( { fromStateSetting: true } ); - this.setNotificationsDeferred( true ); - return; - } + phetioStateEngine.onBeforeStateSetEmitter.addListener( isInStateScope => { + + // Only clear if this PhetioDynamicElementContainer is in scope of the state to be set + if ( isInStateScope( this.tandem ) ) { + this.clear( { fromStateSetting: true } ); + this.setNotificationsDeferred( true ); } } );